[Tux4kids-commits] r1230 - in tuxmath/branches/lan: server src
David Bruce
dbruce-guest at alioth.debian.org
Sat Jul 18 02:45:17 UTC 2009
Author: dbruce-guest
Date: 2009-07-18 02:45:15 +0000 (Sat, 18 Jul 2009)
New Revision: 1230
Modified:
tuxmath/branches/lan/server/server.c
tuxmath/branches/lan/server/testclient.c
tuxmath/branches/lan/server/transtruct.h
tuxmath/branches/lan/src/network.c
Log:
further implementation of messaging
Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c 2009-07-18 01:27:06 UTC (rev 1229)
+++ tuxmath/branches/lan/server/server.c 2009-07-18 02:45:15 UTC (rev 1230)
@@ -509,7 +509,7 @@
-void handle_client_nongame_msg(int i,char *buffer)
+void handle_client_nongame_msg(int i, char* buffer)
{
if(strncmp(buffer, "START_GAME", strlen("START_GAME")) == 0)
{
@@ -522,7 +522,7 @@
}
-int handle_client_game_msg(int i , char *buffer)
+int handle_client_game_msg(int i , char* buffer)
{
#ifdef LAN_DEBUG
printf("Buffer received from client: %s\n", buffer);
@@ -542,7 +542,7 @@
{
game_msg_next_question();
}
- else if(strncmp(buffer, "LEAVE_GAME",strlen("LEAVE_GAME")) == 0)
+ else if(strncmp(buffer, "LEAVE_GAME", strlen("LEAVE_GAME")) == 0)
{
client[i].game_ready = 0; /* Player quitting game but not disconnecting */
}
Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c 2009-07-18 01:27:06 UTC (rev 1229)
+++ tuxmath/branches/lan/server/testclient.c 2009-07-18 02:45:15 UTC (rev 1230)
@@ -112,7 +112,11 @@
else if (strncmp(buffer, "game", 4) == 0)
{
playgame();
- printf("Math game finished.\n");
+ printf("Math game finished.\n\n");
+ printf("Type:\n"
+ "'game' to start math game;\n"
+ "'exit' to end client leaving server running;\n"
+ "'quit' to end both client and server\n>\n");
}
else
{
@@ -167,6 +171,22 @@
else
printf("Unable to parse buffer into FlashCard\n");
}
+ else if(strncmp(buf, "ADD_QUESTION", strlen("ADD_QUESTION")) == 0)
+ {
+ /* function call to parse buffer and receive question */
+ if(Make_Flashcard(buf, &flash))
+ {
+ have_question = 1;
+ printf("The question is: %s\n>\n", flash.formula_string);
+ }
+ else
+ printf("Unable to parse buffer into FlashCard\n");
+ }
+ else if(strncmp(buf, "REMOVE_QUESTION", strlen("REMOVE_QUESTION")) == 0)
+ {
+ //remove the question (i.e. comet in actual game) with given id
+ }
+
else if(strncmp(buf, "SEND_MESSAGE", strlen("SEND_MESSAGE")) == 0)
{
printf("%s\n", buf);
@@ -175,6 +195,14 @@
{
player_msg_recvd(buf);
}
+ else if(strncmp(buf, "TOTAL_QUESTIONS", strlen("TOTAL_QUESTIONS")) == 0)
+ {
+ //update the "questions remaining" counter
+ }
+ else if(strncmp(buf, "MISSION_ACCOMPLISHED", strlen("MISSION_ACCOMPLISHED")) == 0)
+ {
+ //means player won the game!
+ }
else
{
printf("game_check_msgs() - unrecognized message: %s\n", buf);
Modified: tuxmath/branches/lan/server/transtruct.h
===================================================================
--- tuxmath/branches/lan/server/transtruct.h 2009-07-18 01:27:06 UTC (rev 1229)
+++ tuxmath/branches/lan/server/transtruct.h 2009-07-18 02:45:15 UTC (rev 1230)
@@ -14,7 +14,7 @@
#ifndef TRANSTRUCT_H
#define TRANSTRUCT_H
-//#define LAN_DEBUG
+#define LAN_DEBUG
#define NET_BUF_LEN 512
#define DEFAULT_PORT 4779
#define NAME_SIZE 50
Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c 2009-07-18 01:27:06 UTC (rev 1229)
+++ tuxmath/branches/lan/src/network.c 2009-07-18 02:45:15 UTC (rev 1230)
@@ -133,7 +133,7 @@
char buf[NET_BUF_LEN];
snprintf(buf, NET_BUF_LEN,
- "%s\n",
+ "%s",
"NEXT_QUESTION");
return say_to_server(buf);
}
@@ -141,7 +141,7 @@
int check_messages(char buf[NET_BUF_LEN])
{
- int x = 0, numready;
+ int numready;
//This is supposed to check to see if there is activity:
numready = SDLNet_CheckSockets(set, 0);
@@ -156,12 +156,11 @@
#ifdef LAN_DEBUG
// printf("There are %d sockets with activity!\n", numready);
#endif
- // check all sockets with SDLNet_SocketReady and handle the active ones.
+ // check socket with SDLNet_SocketReady and handle if active:
if(SDLNet_SocketReady(sd))
{
buf[0] = '\0';
- x = SDLNet_TCP_Recv(sd, buf, NET_BUF_LEN);
- if( x <= 0)
+ if(SDLNet_TCP_Recv(sd, buf, NET_BUF_LEN) <= 0)
{
fprintf(stderr, "In play_game(), SDLNet_TCP_Recv() failed!\n");
exit(EXIT_FAILURE);
@@ -298,7 +297,7 @@
int LAN_NotAnsweredCorrectly(MC_FlashCard* fc)
{
char buffer[NET_BUF_LEN];
- snprintf(buffer, NET_BUF_LEN, "%s %d\n", "WRONG_ANSWER", fc->question_id);
+ snprintf(buffer, NET_BUF_LEN, "%s\t%d", "WRONG_ANSWER", fc->question_id);
return say_to_server(buffer);
}
More information about the Tux4kids-commits
mailing list