From: Colin L. <col...@us...> - 2002-07-19 16:43:06
|
Update of /cvsroot/dudusdl/dudusdl/src In directory usw-pr-cvs1:/tmp/cvs-serv27294 Modified Files: board.c loading.c network.c network.h Log Message: boards sync Index: board.c =================================================================== RCS file: /cvsroot/dudusdl/dudusdl/src/board.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- board.c 19 Jul 2002 13:21:02 -0000 1.3 +++ board.c 19 Jul 2002 16:43:01 -0000 1.4 @@ -19,19 +19,52 @@ */ #include "dudusdl.h" - +#include "network.h" +#include <string.h> //initialise les tableaux de tableauJeu void initialiser_tableau () { int n,i; + char *c; srand (time (NULL)); + if(!network || server) + for (n = 0; n <= nombreJoueurs; n++) + { + if(n==0) send_data_unfinished("sc"); + if(n==1) send_data_unfinished("cc"); + for(i=0; i < 48; i++) { + getBulle(n,i).couleur = (int)((6.0 * rand()) / (RAND_MAX)); + c=malloc(sizeof(char)); + sprintf(c,"%d",getBulle(n,i).couleur); + send_data_unfinished(c); + } + send_data("",NULL,0); + + } + if(network && !server) + for (n = 0; n <= nombreJoueurs; n++) + { char * data = NULL; + while(!check_incoming_network()) { usleep(50); } + data = malloc(50); + data = get_waiting(); + if(strncmp(data,"sc",2) == 0) { + for (i=0; i < 48; i++) + getBulle(1,i).couleur = data[i+2] - 48; + } + if(strncmp(data,"cc",2) == 0) { + for (i=0; i < 48; i++) + getBulle(0,i).couleur = data[i+2] - 48; + + } + } + for (n = 0; n <= nombreJoueurs; n++) { for(i=0, joueur[n].bulleCourante = 0; joueur[n].bulleCourante < 48; joueur[n].bulleCourante ++, i++) { - getBulle(n,i).couleur = (int)((6.0 * rand()) / (RAND_MAX)); + //getBulle(n,i).couleur = (int)((6.0 * rand()) / (RAND_MAX)); getBulle(n,i).Y = joueur[n].tableau[2]+8 + 16 * (i/12); if ( (i/12)%2 == 0) Index: loading.c =================================================================== RCS file: /cvsroot/dudusdl/dudusdl/src/loading.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- loading.c 19 Jul 2002 13:06:44 -0000 1.7 +++ loading.c 19 Jul 2002 16:43:01 -0000 1.8 @@ -105,9 +105,9 @@ network_ready = check_incoming_network() || network_ready; if(new_conn != network_ready && server) { net_param[0]=modeViolent; - send_data("mv",net_param); + send_data("mv",net_param,1); net_param[0]=gravite; - send_data("mg",net_param); + send_data("mg",net_param,1); } data = get_waiting(); if(data != NULL) { @@ -195,13 +195,13 @@ modeViolent = !modeViolent; PutPic (285 + modeViolent, 350, 215); net_param[0]=modeViolent; - if(network && server) send_data("mv",net_param); + if(network && server) send_data("mv",net_param,1); break; case 3: gravite = !gravite; PutPic (285 + gravite, 350, 285); net_param[0]=gravite; - if(network && server) send_data("mg",net_param); + if(network && server) send_data("mg",net_param,1); break; default: Quit("Bug dans demander parametres\n"); @@ -225,13 +225,13 @@ modeViolent = !modeViolent; PutPic (285 + modeViolent, 350, 215); net_param[0]=modeViolent; - if(network && server) send_data("mv",net_param); + if(network && server) send_data("mv",net_param,1); break; case 3: gravite = !gravite; PutPic (285 + gravite, 350, 285); net_param[0]=gravite; - if(network && server) send_data("mg",net_param); + if(network && server) send_data("mg",net_param,1); break; default: Quit("Bug dans demander parametres\n"); @@ -240,12 +240,12 @@ case SDLK_RETURN: if(network && !server) break; if(!network || network_ready) { - if(network && server) send_data("go",NULL); + if(network && server) send_data("go",NULL,0); done = 1; } break; case SDLK_ESCAPE: - if(network) send_data(":x",NULL); + if(network) send_data(":x",NULL,0); exit(0); break; default: Index: network.c =================================================================== RCS file: /cvsroot/dudusdl/dudusdl/src/network.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- network.c 19 Jul 2002 13:06:44 -0000 1.4 +++ network.c 19 Jul 2002 16:43:01 -0000 1.5 @@ -110,44 +110,53 @@ char * waiting_data = NULL; void parse_data (void) { - char buf[80]; - int nb_read=0; - char * t=NULL; - if((nb_read = read(client_sock, &buf, 80)) < 0) { + char c,buf[100]; + int nb_read=0,pos=0; + if((nb_read = read(client_sock, &c, 1)) < 0) { printf("Connection lost !\n"); close(client_sock); client_sock=0; } else if(nb_read > 0) { - waiting_data = NULL; - printf("received: %s\n",buf); + while(c!='!') { + buf[pos]=c; + pos++; + read(client_sock, &c, 1); + } + buf[pos]='\0'; waiting_data = strdup(buf); } - printf("returning\n"); + printf("returning (%s)\n",waiting_data); } char * get_waiting(void) { - char * res = NULL; - if (waiting_data != NULL) - res = strdup(waiting_data); - waiting_data = NULL; - return res; - + return waiting_data; } -void send_data(char * msg, int params[]) { +void send_data(char * msg, int params[],int len) { char * send = NULL; int i; send=strdup(msg); if(params != NULL) { - for(i=0;i<sizeof(params);i+=sizeof(int)) { + for(i=0;i<len;i++) { sprintf(send,"%s%d",send,params[i]); } } - printf("sending %s\n",send); + sprintf(send,"%s!",send); + printf("sending %s(%d)\n",send,strlen(send)); + if(client_sock <= 0) { + printf("client_sock closed\n"); + return; + } + write(client_sock, send, strlen(send)); + +} + +void send_data_unfinished(char * msg) { + printf("sending %s(%d)\n",msg,strlen(msg)); if(client_sock <= 0) { printf("client_sock closed\n"); return; } - write(client_sock, send, sizeof(send)); + write(client_sock, msg, strlen(msg)); } Index: network.h =================================================================== RCS file: /cvsroot/dudusdl/dudusdl/src/network.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- network.h 19 Jul 2002 13:06:44 -0000 1.2 +++ network.h 19 Jul 2002 16:43:01 -0000 1.3 @@ -42,6 +42,7 @@ void send_state_to_server (void); void get_state_from_server (void); int check_incoming_network (void); -void send_data (char * msg, int param[]); +void send_data (char * msg, int param[], int len); +void send_data_unfinished (char * msg); char * get_waiting (void); #endif |