[Tux4kids-commits] r1068 - tuxmath/branches/lan/server
akash gangil
gangil-guest at alioth.debian.org
Thu Jun 18 17:55:45 UTC 2009
Author: gangil-guest
Date: 2009-06-18 17:55:44 +0000 (Thu, 18 Jun 2009)
New Revision: 1068
Modified:
tuxmath/branches/lan/server/server.c
tuxmath/branches/lan/server/server.h
tuxmath/branches/lan/server/testclient.c
Log:
MC_AnsweredCorrectly works fine
Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c 2009-06-18 13:10:59 UTC (rev 1067)
+++ tuxmath/branches/lan/server/server.c 2009-06-18 17:55:44 UTC (rev 1068)
@@ -34,7 +34,6 @@
int quit, quit2;
char buffer[NET_BUF_LEN];
int command_type = -1;
- // size_t length;
MC_FlashCard flash;
static int initialize = 0;
int id;
@@ -103,17 +102,15 @@
if(strcmp(command,"CORRECT_ANSWER") == 0)
{
command_type = CORRECT_ANSWER;
- }
-
- //'a' for the setting up the question list
- if(strcmp(command,"a") == 0)
+ }
+ //'a' for the setting up the question list
+ else if(strcmp(command,"a") == 0)
{
initialize=1;
command_type = NEW_GAME;
}
-
//'b' for asking for a question(flashcard)
- if(strcmp(command,"b") == 0)
+ else if(strcmp(command,"b") == 0)
{
printf("received request to send question\n");
if(!initialize)
@@ -123,19 +120,18 @@
else
command_type = SEND_A_QUESTION;
}
-
- if(strcmp(command, "exit") == 0) /* Terminate this connection */
+ else if(strcmp(command, "exit") == 0) /* Terminate this connection */
{
quit2 = 1;
printf("Terminate connection\n");
}
-
- if(strcmp(command, "quit") == 0) /* Quit the program */
+ else if(strcmp(command, "quit") == 0) /* Quit the program */
{
quit2 = 1;
quit = 1;
printf("Quit program\n");
}
+ else;
switch(command_type)
{
@@ -154,7 +150,7 @@
case CORRECT_ANSWER:
{
- if(!SendMessage(ANSWER_CORRECT, 0))
+ if(!SendMessage(ANSWER_CORRECT,id))
{
printf("Unable to communicate to the client\n");
}
@@ -220,7 +216,6 @@
int SendQuestion(MC_FlashCard flash)
{
int x;
-
char buf[NET_BUF_LEN];
snprintf(buf, NET_BUF_LEN,
"%s\t%d\t%d\t%d\t%s\t%s\n",
Modified: tuxmath/branches/lan/server/server.h
===================================================================
--- tuxmath/branches/lan/server/server.h 2009-06-18 13:10:59 UTC (rev 1067)
+++ tuxmath/branches/lan/server/server.h 2009-06-18 17:55:44 UTC (rev 1068)
@@ -16,7 +16,7 @@
#ifndef SERVER_H
#define SERVER_H
-
+/*enum for commands coming from the client side*/
enum {
NEW_GAME,
SEND_A_QUESTION,
Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c 2009-06-18 13:10:59 UTC (rev 1067)
+++ tuxmath/branches/lan/server/testclient.c 2009-06-18 17:55:44 UTC (rev 1068)
@@ -1,5 +1,5 @@
/*
-* C Implementation: server.c
+* C Implementation: testclient.c
*
* Description: Test client program for LAN-based play in Tux,of Math Command.
*
@@ -71,7 +71,7 @@
// Create a socket set to handle up to 16 sockets
// NOTE 16 taken from example - almost certainly don't need that many
- set = SDLNet_AllocSocketSet(16);
+ set = SDLNet_AllocSocketSet(1); // it has to be one since this is client and it has to communicate with ONLY 1 SERVER.
if(!set) {
printf("SDLNet_AllocSocketSet: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
@@ -122,6 +122,9 @@
}
SDLNet_TCP_Close(sd);
+ SDLNet_FreeSocketSet(set);
+ set=NULL; //this helps us remember that this set is not allocated
+
SDLNet_Quit();
return EXIT_SUCCESS;
@@ -288,11 +291,11 @@
{
have_question = 0;
//Tell server we answered it right:
-/* if(!MC_AnsweredCorrectly(&flash))
+ if(!MC_AnsweredCorrectly(&flash))
{
printf("Unable to communicate the same to server\n");
exit(EXIT_FAILURE);
- }*/
+ }
//and ask it to send us the next one:
//Ask for first question:
snprintf(buf, NET_BUF_LEN, "%s\n", "b");
More information about the Tux4kids-commits
mailing list