src/server.c

changeset 64
4eda5df55f86
parent 60
0c50aac49e55
equal deleted inserted replaced
63:611332453da0 64:4eda5df55f86
67 67
68 dump_gameinfo(&(settings->gameinfo)); 68 dump_gameinfo(&(settings->gameinfo));
69 GameState continuegame; 69 GameState continuegame;
70 gamestate_init(&continuegame); 70 gamestate_init(&continuegame);
71 if (settings->continuepgn) { 71 if (settings->continuepgn) {
72 // preload PGN data before handshake 72 /* preload PGN data before handshake */
73 FILE *pgnfile = fopen(settings->continuepgn, "r"); 73 FILE *pgnfile = fopen(settings->continuepgn, "r");
74 if (pgnfile) { 74 if (pgnfile) {
75 int result = read_pgn(pgnfile, &continuegame, 75 int result = read_pgn(pgnfile, &continuegame,
76 &(settings->gameinfo)); 76 &(settings->gameinfo));
77 long position = ftell(pgnfile); 77 long position = ftell(pgnfile);
104 return 1; 104 return 1;
105 } 105 }
106 106
107 int fd = server.client->fd; 107 int fd = server.client->fd;
108 if (settings->continuepgn) { 108 if (settings->continuepgn) {
109 // Continue game, send PGN data 109 /* Continue game, send PGN data */
110 uint16_t mc = 0; 110 uint16_t mc = 0;
111 MoveList *movelist = continuegame.movelist; 111 MoveList *movelist = continuegame.movelist;
112 while (movelist) { 112 while (movelist) {
113 mc++; 113 mc++;
114 movelist = movelist->next; 114 movelist = movelist->next;
131 memcpy(pgndata+sizeof(GameInfo)+sizeof(mc), moves, mc*sizeof(Move)); 131 memcpy(pgndata+sizeof(GameInfo)+sizeof(mc), moves, mc*sizeof(Move));
132 free(moves); 132 free(moves);
133 net_send_data(fd, NETCODE_PGNDATA, pgndata, pgndata_size); 133 net_send_data(fd, NETCODE_PGNDATA, pgndata, pgndata_size);
134 free(pgndata); 134 free(pgndata);
135 } else { 135 } else {
136 // Start new game 136 /* Start new game */
137 net_send_data(fd, NETCODE_GAMEINFO, 137 net_send_data(fd, NETCODE_GAMEINFO,
138 &(settings->gameinfo), sizeof(GameInfo)); 138 &(settings->gameinfo), sizeof(GameInfo));
139 } 139 }
140 addstr("\rClient connected - awaiting challenge acceptance..."); 140 addstr("\rClient connected - awaiting challenge acceptance...");
141 refresh(); 141 refresh();

mercurial