• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
YyYo

Preventing cheating on game's server side

7 posts in this topic

HI...

 

A few weeks ago I started to implement my first multiplayer game(Java/Android)

The game is turn-base game similar to tic-tac-toe and players can Chat during the game.

The server always knows who is the current player.

since I need to support chatting no matter who's turn it is, I collect ALL messages from both players.

Chat messages are stored in a dedicated queue and broadcast to players.

Game messages are also stored in a dedicate queue.

 

Now comes the problematic part:

Lets say one of the player is cheating, and manage to send a "move" message to server even though its not is turn, how can I "recover" from this situation.

I have a solution for it, by start polling messages from game queue. if the message is not belong to current player i ignore it. if the message is belong to current player, I update game and switch turn to next user.

Is this solution is the correct one or there is something more simpler/elegant ???

 

I added a snapshot of pseudo code:

package ServerGame;

import java.util.Iterator;
import java.util.Queue;

class GameManager extends Thread{
	Player currentPlayer;
	Queue<Player> players;
	Queue<String> chatMessages;
	Queue<String> gameMessages;
	public void run(){
		String message;
		while(true){
			for(Player player : players){
				if(player.isReadAvailable()){		// check if there is a message sent from client 
					message = player.doRead();		// read message content
					router(message);				// route the message according to its type: game | chat
				}
			}
			broadcastChatMessages();				// send chat messages to all players
			updateGame();							// update game
		}
	}
		
	private void updateGame(){							
		for(Iterator<String> iterator = gameMessages.iterator() ; iterator.hasNext() ; ){
			String message = iterator.next();
			if(currentPlayer.isYours(message)){
				// handle message
				if(message.type ==”move”){				
					updateBoard();			// process the move and do a switch turn to opponent
					
				}
				switchTurn();
			}
			else{							// ignore messages that are not belong to current player(avoid cheating)
				iterator.remove();
			}
		}
	}
	
	private void broadcastChatMessages(){
		for(String message : chatMessages){
			for(Player player : players){
				player.doWrite(message);
				}
			}
	}

	private void router(String message){
		if(message == null){
			return;
		}
		if(message.proprietary == “CHAT”){
			chatMessages.add(message);
		}
		else if(message.proprietary == “GAME”){
			gameMessages.add(message);
		}
		else{
			// ignore message - maybe log it 
		}
			
	}

	
}
0

Share this post


Link to post
Share on other sites

I think that's OK, if the cheat is sending a message to the queue when it's not their turn, checking and discarding those messages is the solution that makes more sense.

 

Another option could be to prevent the board to be updated 2 consecutive times by the same player (inside updateBoard), but it doesn't make sense that you proccess everything needed to make a move if you can detect the move isn't valid when it arrives.

1

Share this post


Link to post
Share on other sites

First thanks for the fast response.

 

didn't understand what doesn't make sense

 but it doesn't make sense that you proccess everything needed to make a move if you can detect the move isn't valid when it arrives.

 

what I do in updateGame is to loop all "movement" messages in queue, and ignore messages not belonging to current player.

Can you please explain again?

0

Share this post


Link to post
Share on other sites

BTW: isn't it better to CLEAN gameMessages queue after I make a move for the current player??

 

Since it is a turn-base game, which each player can make a single move, isn't it better to empty gameMessage queue?

It can prevent for cheater which try to 'attack' the game, by sending multiple messages to game when its not their turn.

I will adopt your idea which each player can't 

 

 

updated 2 consecutive times by the same player

 

but then the gameMessage queue will still contain "garbage" messages

 

am I right ??

Edited by YyYo
0

Share this post


Link to post
Share on other sites

If you process the next message in the input queue as soon as it is there, and discard messages that are against the rules, then the "cleaning" will happen by itself, because if someone sends a second message, that will immediately be discarded (because it's against the rules.)

1

Share this post


Link to post
Share on other sites

First thanks for the fast response.

 

didn't understand what doesn't make sense

 but it doesn't make sense that you proccess everything needed to make a move if you can detect the move isn't valid when it arrives.

 

what I do in updateGame is to loop all "movement" messages in queue, and ignore messages not belonging to current player.

Can you please explain again?

Sorry, I meant that it wouldn't make sense. If you decide to ignore the move inside updateBoard instead of your current solution, you'll be processing the message when you could have detected it was invalid before. Maybe here it doesn't make much difference when you do it, but consider this: You decide to track data from each player, and part of that data is how many movements a player does. If you only check for cheats before updating the board you may update that player stats with invalid data. You can move the check to the tracking then and do something to prevent the movement too, but what if you add more features before the tracking? Discarding the message as soon as possible looks like the best option to me, check if it's valid before doing anything else.

 

Maybe I shouldn't have mentioned an option that I think it's bad, sorry if I confused you.

 

 

BTW: isn't it better to CLEAN gameMessages queue after I make a move for the current player??

 

Since it is a turn-base game, which each player can male a single move, isn't it better to empty gameMessage queue?

It can prevent for cheater which try to 'attack' the game, by sending multiple messages to game when its not their turn.

I will adopt your idea which each player can't 

 

 

updated 2 consecutive times by the same player

 

but then the gameMessage queue will still contain "garbage" messages

 

am I right ??

Cleaning the whole queue could be a problem if you can have 2 valid moves at some time in it. Maybe that can't happen in this case, but if you can always clear all the message queue maybe you don't really need a queue. As hplus0603 said, if you check and discard messages you'll basically be cleaning the queue, but you have more control than a .clean() method.

 

I'd stick with your current solution, ignoring the message if it doesn't belong to the current player.

1

Share this post


Link to post
Share on other sites

Ok... lets take following scenario.

There 2 player: playerA & playerB

Current Player: playerA

Lets say both players are cheating and sends the following message order: [ B4 , A3 , A2 , B3 , A1 , B2 , B1] -> pollFirst()

If I decide to discard message before insert them to quaue, the following will happend in main loop:

1th iteration: B1 will be discarded and updateBoard wont do nothing(since queue is empty)

2th iteration: B2 will be discarded and updateBoard wont do nothing

3th iteration: A1 will be accepted and updateBoard will make the move and change the turn to playerB

4th iteration: B3 will be accepted and updateBoard will make the move and change the turn to playerA

5th iteration: A2 will be accepted and updateBoard will make the move and change the turn to playerB

6th iteration: A3 will be discarded and updateBoard wont do nothing.

7th iteration: B4 will be accepted and updateBoard will make the move and change the turn to playerA

 

is this what you ment to discard message before insert them to queue?

 

 

Discarding the message as soon as possible looks like the best option to me, check if it's valid before doing anything else.

 

Another thing raises while writing the scenario above(discarding message before adding to queue...)

It seems that the first valid message is processed immidiatly by updateGame(), and when finish updating, it pass the turn to next player.

It seems that the queue always have single valid message in queue at any time, so I guess I don't ready need the queue.

Am I wright or I'm starting to get a little confused ???

Edited by YyYo
0

Share this post


Link to post
Share on other sites

My experience is that the simplest solution is the most robust.

Thus, when you receive a message, all you do is enqueue it in the message queue, and you're done.

The message queueing process then simply runs a loop that dequeues messages and handles them, one at a time.

Part of handling a message is determining "do the game rules allow this message at this time?"

If the game state has the value "it's red's turn" and you dequeue a message that says "blue makes a turn," then that's against the rules, and gets rejected by that logic.

The good news here is that each step is very focused, and knows what to do; there is no diffusion of state between different stages. If you have to have the network code "know" whose turn it "will be" in order to insert a message or not, you have a back pointing arc in your flow/dependency diagram, that will cause structural problems (and sometimes even deadlocks.)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0