コード例 #1
0
ファイル: client2.c プロジェクト: guysalama/CN_ex1
void handleMsg(char *buf){
	int oldMyTurn = game.isMyTurn;

	struct gameData currGame;
	assert(9 <= parseGameData(buf, &currGame));
	if (currGame.msg != 2){//it's a message!
		char txt[MSGTXT_SIZE];
		strncpy(txt, currGame.msgTxt, strlen(currGame.msgTxt));
		txt[strlen(currGame.msgTxt)] = '\0';
		printf("Client %d: %s\n", currGame.msg + 1, txt);
		return;
	}
	//it's a turn!
	assert(11 <= parseGameData(buf, &game));
	//updateStaticParams(); TODO
	myTurn = game.isMyTurn;

	if (oldMyTurn == 1 && myTurn == 0){//turn is changed. I must have sent a move!
		if (game.valid == 1){
			printf(LEGAL_MOVE);
		}
		else{
			printf(ILLEGAL_MOVE);
		}
	}
	if (oldMyTurn == 0 && myTurn == 1){
		if (game.LastTurnHeap == -1){
			printf("Client %d made an illegal move", opponentId());
		}
		else {
			printf("Client %d takes %d cubes from Heap %c", opponentId(), game.LastTurnRemoves, (char)(game.LastTurnHeap + (int)'A'));
		}
	}
	if (myTurn != 1){
		printGameState(game);
	}
	if (myTurn == 1 && game.win == -1){
		printf(YOUR_TURN);
	}
}
コード例 #2
0
ファイル: Server.c プロジェクト: dorbank/Computer-Networking
void sendClientConnected(int fd, struct gameData *data){
	struct clientData thisClientData;
	char buf[MSG_SIZE];

	// last one added	
	thisClientData = ClientsQueue[conViewers+conPlayers]; 

	data->valid = 1;
	data->msg = 0;
	data->myPlayerId = thisClientData.clientNum;
	data->playing = thisClientData.isPlayer;

	parseGameData(buf, data);
	int errorIndicator = sendAll(fd, buf, &msg_SIZE);
	checkForNegativeValue(errorIndicator, "send", fd);
	
}
コード例 #3
0
ファイル: ClientNew.c プロジェクト: guysalama/CN_ex1
////////////////////// message handlers /////////////////////////////
void handleFirstMsg(char *buf){
	parseGameData(buf, &game);
}