[Tux4kids-commits] r1218 - in tuxmath/branches/lan: server src
David Bruce
dbruce-guest at alioth.debian.org
Thu Jul 16 02:22:56 UTC 2009
Author: dbruce-guest
Date: 2009-07-16 02:22:50 +0000 (Thu, 16 Jul 2009)
New Revision: 1218
Modified:
tuxmath/branches/lan/server/testclient.c
tuxmath/branches/lan/src/network.c
tuxmath/branches/lan/src/network.h
Log:
code cleanup and implementation of LAN_LeaveGame()
Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c 2009-07-15 22:26:21 UTC (rev 1217)
+++ tuxmath/branches/lan/server/testclient.c 2009-07-16 02:22:50 UTC (rev 1218)
@@ -234,13 +234,7 @@
{
end = 1; //Exit our loop in playgame()
//Tell server we are quitting current game:
- //FIXME make into LAN_LeaveGame()
- snprintf(buf, NET_BUF_LEN, "%s", "LEAVE_GAME");
- if (SDLNet_TCP_Send(sd, (void *)buf, NET_BUF_LEN) < NET_BUF_LEN)
- {
- fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
- return -1;
- }
+ LAN_LeaveGame();
}
else
{
Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c 2009-07-15 22:26:21 UTC (rev 1217)
+++ tuxmath/branches/lan/src/network.c 2009-07-16 02:22:50 UTC (rev 1218)
@@ -41,11 +41,6 @@
int LAN_Setup(char *host, int port)
{
IPaddress ip; /* Server address */
-// int len;
-// char buf[NET_BUF_LEN]; // for network messages from server
- char buffer[NET_BUF_LEN]; // for command-line input
-// char *check1;
- char name[NAME_SIZE]="Player 1";
if (SDLNet_Init() < 0)
{
@@ -106,15 +101,9 @@
int LAN_SetName(char* name)
{
char buf[NET_BUF_LEN];
-
if(!name)
return 0;
-
- snprintf(buf, NET_BUF_LEN,
- "%s\t%s",
- "SET_NAME",
- name);
-
+ snprintf(buf, NET_BUF_LEN, "%s\t%s", "SET_NAME", name);
return say_to_server(buf);
}
@@ -293,55 +282,38 @@
int LAN_StartGame(void)
{
char buffer[NET_BUF_LEN];
- snprintf(buffer, NET_BUF_LEN,
- "%s\n",
- "START_GAME");
- if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
- {
- fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
- return 0;
- }
-#ifdef LAN_DEBUG
- printf("Sent the game notification %s\n",buffer);
-#endif
- return 1;
+ snprintf(buffer, NET_BUF_LEN, "%s", "START_GAME");
+ return say_to_server(buffer);
}
int LAN_AnsweredCorrectly(MC_FlashCard* fc)
{
char buffer[NET_BUF_LEN];
-
- snprintf(buffer, NET_BUF_LEN,
- "%s %d\n",
- "CORRECT_ANSWER",
- fc->question_id);
- if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
- {
- fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
- exit(EXIT_FAILURE);
- }
- return 1;
+ snprintf(buffer, NET_BUF_LEN, "%s %d", "CORRECT_ANSWER", fc->question_id);
+ return say_to_server(buffer);
}
-
+
+
int LAN_NotAnsweredCorrectly(MC_FlashCard* fc)
{
- int len;
char buffer[NET_BUF_LEN];
+ snprintf(buffer, NET_BUF_LEN, "%s %d\n", "WRONG_ANSWER", fc->question_id);
+ return say_to_server(buffer);
+}
- snprintf(buffer, NET_BUF_LEN,
- "%s %d\n",
- "WRONG_ANSWER",
- fc->question_id);
- len = strlen(buffer) + 1;
- if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
- {
- fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
- exit(EXIT_FAILURE);
- }
- return 1;
+
+/* This tells the server we are quitting the current math game, but */
+/* not disconnecting our socket: */
+int LAN_LeaveGame(void)
+{
+ char buf[NET_BUF_LEN];
+ snprintf(buf, NET_BUF_LEN, "%s", "LEAVE_GAME");
+ return say_to_server(buf);
}
+
+
/*private to network.c functions*/
int say_to_server(char* statement)
Modified: tuxmath/branches/lan/src/network.h
===================================================================
--- tuxmath/branches/lan/src/network.h 2009-07-15 22:26:21 UTC (rev 1217)
+++ tuxmath/branches/lan/src/network.h 2009-07-16 02:22:50 UTC (rev 1218)
@@ -28,12 +28,15 @@
/* Network replacement functions for mathcards "API": */
/* These functions are how the client tells things to the server: */
int LAN_StartGame(void);
+/* NOTE probably won't have this in multiplayer - new quests determined by server */
int LAN_NextQuestion(void);
int LAN_AnsweredCorrectly(MC_FlashCard* fc);
int LAN_NotAnsweredCorrectly(MC_FlashCard* fc);
+int LAN_LeaveGame(void);
/* This is how the client receives messages from the server: */
int LAN_NextMsg(char* buf);
+
/* Functions to handle various messages from the server: */
/* NOTE not sure if these belong here or in game.c/testclient.c */
int player_msg_recvd(char* buf);
More information about the Tux4kids-commits
mailing list