File: inputfd.c

package info (click to toggle)
teg 0.9.2-2.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,232 kB
  • ctags: 2,372
  • sloc: ansic: 18,999; sh: 9,273; makefile: 589; yacc: 318; xml: 160
file content (1510 lines) | stat: -rw-r--r-- 32,195 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
/*	$Id: inputfd.c,v 1.80 2001/12/21 22:10:01 riq Exp $	*/
/* Tenes Empanadas Graciela
 *
 * Copyright (C) 2000 Ricardo Quesada
 *
 * Author: Ricardo Calixto Quesada <rquesada@core-sdi.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; only version 2 of the License
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */
/**
 * @file inputfd.c
 * Maneja los 'tokens' de entrada
 */
#include <string.h>
#include <stdio.h>

#include "client.h"

TEG_STATUS clitok_rem(char *str);
TEG_STATUS clitok_status(char *str);
TEG_STATUS clitok_start(char *str);
TEG_STATUS clitok_playerid(char *str);
TEG_STATUS clitok_newplayer(char *str);
TEG_STATUS clitok_message(char *str);
TEG_STATUS clitok_paises(char *str);
TEG_STATUS clitok_fichas(char *str);
TEG_STATUS clitok_fichas2(char *str);
TEG_STATUS clitok_fichasc(char *str);
TEG_STATUS clitok_turno(char *str);
TEG_STATUS clitok_ataque(char *str);
TEG_STATUS clitok_dados(char *str);
TEG_STATUS clitok_pais(char *str);
TEG_STATUS clitok_error(char *str);
TEG_STATUS clitok_ok(char *str);
TEG_STATUS clitok_tropas(char *str);
TEG_STATUS clitok_tarjeta(char *str);
TEG_STATUS clitok_canje(char *str);
TEG_STATUS clitok_modalidad(char *str);
TEG_STATUS clitok_objetivo(char *str);
TEG_STATUS clitok_winner( char *str );
TEG_STATUS clitok_lost( char *str );
TEG_STATUS clitok_exit( char *str );
TEG_STATUS clitok_pversion( char *str );
TEG_STATUS clitok_sversion( char *str );
TEG_STATUS clitok_ggz( char *str );
TEG_STATUS clitok_serverfull(void);
TEG_STATUS clitok_surrender(char *str);
TEG_STATUS clitok_empezado(void);
TEG_STATUS clitok_kick(char *str);
TEG_STATUS clitok_scores(char *str);
TEG_STATUS clitok_reconnect(char *str);
TEG_STATUS clitok_enum_cards( char *str );
TEG_STATUS clitok_playersscores( char *str );

struct {
	char *label;
	TEG_STATUS (*func) ();
} tokens[] = {
	{ TOKEN_REM,		clitok_rem 	},
	{ TOKEN_STATUS,		clitok_status 	},
	{ TOKEN_START,		clitok_start 	},
	{ TOKEN_PLAYERID,	clitok_playerid	},
	{ TOKEN_NEWPLAYER,	clitok_newplayer},
	{ TOKEN_MESSAGE,	clitok_message	},
	{ TOKEN_PAISES,		clitok_paises	},
	{ TOKEN_FICHAS,		clitok_fichas	},
	{ TOKEN_FICHAS2,	clitok_fichas2	},
	{ TOKEN_FICHASC,	clitok_fichasc	},
	{ TOKEN_TURNO,		clitok_turno	},
	{ TOKEN_ATAQUE,		clitok_ataque	},
	{ TOKEN_DADOS,		clitok_dados	},
	{ TOKEN_PAIS,		clitok_pais	},
	{ TOKEN_ERROR,		clitok_error	},
	{ TOKEN_OK,		clitok_ok	},
	{ TOKEN_TROPAS,		clitok_tropas	},
	{ TOKEN_TARJETA,	clitok_tarjeta	},
	{ TOKEN_CANJE,		clitok_canje	},
	{ TOKEN_MODALIDAD,	clitok_modalidad},
	{ TOKEN_OBJETIVO,	clitok_objetivo	},
	{ TOKEN_WINNER,		clitok_winner	},
	{ TOKEN_LOST,		clitok_lost	},
	{ TOKEN_EXIT,		clitok_exit	},
	{ TOKEN_PVERSION,	clitok_pversion	},
	{ TOKEN_SVERSION,	clitok_sversion	},
	{ TOKEN_SURRENDER,	clitok_surrender},
#ifdef WITH_GGZ
	{ TOKEN_GGZ,		clitok_ggz	},
#endif /* WITH_GGZ */
	{ TOKEN_SERVERFULL,	clitok_serverfull},
	{ TOKEN_GAMEINPROGRESS,	clitok_empezado	},
	{ TOKEN_KICK,		clitok_kick	},
	{ TOKEN_SCORES,		clitok_scores	},
	{ TOKEN_RECONNECT,	clitok_reconnect},
	{ TOKEN_ENUM_CARDS,	clitok_enum_cards},

};
#define	NRCLITOKENS  (sizeof(tokens)/sizeof(tokens[0]))

struct {
	char *label;
	TEG_STATUS (*func) ();
} err_tokens[] = {
	{ TOKEN_FICHAS,		fichas_restore_from_error },
	{ TOKEN_FICHAS2,	fichas2_restore_from_error },
	{ TOKEN_FICHASC,	fichasc_restore_from_error },
	{ TOKEN_REAGRUPE,	reagrupe_restore_from_error },
	{ TOKEN_EJER2,		ejer2_restore_from_error },
	{ TOKEN_PLAYERID,	playerid_restore_from_error },
	{ TOKEN_START,		aux_start_error },
};
#define	NRERRCLITOKENS  (sizeof(err_tokens)/sizeof(err_tokens[0]))

/**
 * @fn TEG_STATUS clitok_serverfull( void )
 */
TEG_STATUS clitok_serverfull( void )
{
	textmsg( M_ERR, _("The server is full. Try connecting as an observer"));
	desconectar();
	return TEG_STATUS_SUCCESS;
}

/**
 * @fn TEG_STATUS clitok_empezado( void )
 */
TEG_STATUS clitok_empezado( void )
{
	textmsg( M_ERR, _("The game has already started. Try connecting as an observer."));
	desconectar();
	return TEG_STATUS_SUCCESS;
}

/**
 * @fn TEG_STATUS clitok_kick( char *name )
 */
TEG_STATUS clitok_kick( char *name )
{
	if( name && strlen(name) )
		textmsg( M_IMP, _("Player %s was kicked from the game"),name);
	return TEG_STATUS_SUCCESS;
}


/**
 * @fn TEG_STATUS clitok_serverfull( void )
 * Informs that a player has surrender
 */
TEG_STATUS clitok_surrender( char *str )
{
	int numjug;
	PJUGADOR pJ;

	numjug = atoi( str );
	if( jugador_whois( numjug, &pJ) != TEG_STATUS_SUCCESS) {
		/* no lo tengo en la base */
		textmsg( M_IMP,_("Player %d abandoned the game"), numjug );
		return TEG_STATUS_SUCCESS;
	}

	textmsg( M_IMP,_("Player %s(%s) abandoned the game"),
				pJ->nombre,
				_(g_colores[pJ->color])
				);

	if( pJ->numjug == WHOAMI() ) {
		ESTADO_SET(JUG_ESTADO_GAMEOVER);
		gui_sensi();
	}

	out_paises();

	gui_surrender(numjug);

	return TEG_STATUS_SUCCESS;
}


/**
 * @fn TEG_STATUS clitok_exit( char *str )
 * Dice que un jugador perdio coneccion o se fue
 */
TEG_STATUS clitok_exit( char *str )
{
	int numjug;
	PJUGADOR pJ;

	numjug = atoi( str );
	if( jugador_whois( numjug, &pJ) != TEG_STATUS_SUCCESS) {
		/* no lo tengo en la base */
		textmsg( M_IMP,_("Player %d exit the game"), numjug );
		return TEG_STATUS_SUCCESS;
	}

	textmsg( M_IMP,_("Player %s(%s) exit the game"),
				pJ->nombre,
				_(g_colores[pJ->color])
				);

	/* dont delete the player, I need the status */
	/* jugador_del( pJ ); */

	if( WHOAMI() == numjug ) {
		/* por alguna razon el server quiere que abandone el juego */
		desconectar();
	}

	return TEG_STATUS_SUCCESS;
}

/**
 * @fn TEG_STATUS clitok_winner( char *str )
 * Dice que un jugador gano
 */
TEG_STATUS clitok_winner( char *str )
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int numjug;
	int objetivo;
	PJUGADOR pJ;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		numjug = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		objetivo = atoi( p.token );
	} else goto error;


	if( jugador_whois( numjug, &pJ) != TEG_STATUS_SUCCESS)
		goto error;

	if( objetivo == -1 ) objetivo = 0;

	if( objetivo < 0 || objetivo >= objetivos_cant() )
		goto error;

	textmsg( M_IMP,_("Player %s(%s) is the WINNER"),
				pJ->nombre,
				_(g_colores[pJ->color])
				);

	gui_winner( pJ->numjug, objetivo );

	ESTADO_SET( JUG_ESTADO_HABILITADO );
	gui_sensi();

	juego_finalize();
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_winner()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_lost( char *str )
 * Dice que un jugador perdio
 */
TEG_STATUS clitok_lost( char *str )
{
	int numjug;
	PJUGADOR pJ;

	numjug = atoi( str );
	if( jugador_whois( numjug, &pJ) != TEG_STATUS_SUCCESS)
		goto error;

	textmsg( M_IMP,_("Player %s(%s) lost the game\n"),
				pJ->nombre,
				_(g_colores[pJ->color])
				);

	if( pJ->numjug == WHOAMI() )
		ESTADO_SET(JUG_ESTADO_GAMEOVER);

	gui_lost( pJ->numjug );

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_lost()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_tropas( char *str)
 * Avisa que se puden pasar algunos ejercitos al pais conquistado
 */
TEG_STATUS clitok_tropas( char *str)
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int src,dst,cant;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		src = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		dst = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		cant = atoi( p.token );
	} else goto error;

	ESTADO_SET(JUG_ESTADO_TROPAS);

	gui_tropas( src,dst,cant);

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_tropas()");
	return TEG_STATUS_ERROR;
}


/**
 * @fn TEG_STATUS clitok_ok( char *str)
 */
TEG_STATUS clitok_ok( char *str)
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_ok()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_error( char *str)
 * Recibe los mensajes de error del servidor
 */
TEG_STATUS clitok_error( char *str)
{
	int i;
	if( strlen(str)==0 )
		goto error;


	for(i = 0; i < NRERRCLITOKENS; i++) {
		if(strcasecmp( str, err_tokens[i].label )==0 ){
			if (err_tokens[i].func)
				return( (err_tokens[i].func)());
			textmsg(M_ERR,_("The server report an error in '%s'"),str);
			return TEG_STATUS_TOKENNULL;
		}
	}
	return TEG_STATUS_SUCCESS;

error:
	textmsg(M_ERR,"Error in clitok_error()");
	return TEG_STATUS_ERROR;
}


/**
 * @fn TEG_STATUS clitok_pais( char *str)
 * Actualiza un solo pais (usado pora tropas, dados, y mas
 */
TEG_STATUS clitok_pais( char *str)
{
	int pais;
	int jug;
	int ejer;

	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		pais = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		jug = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		ejer = atoi( p.token );
	} else goto error;

	g_paises[pais].numjug = jug;
	g_paises[pais].ejercitos = ejer;

	gui_pais( pais );

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_pais()");
	return TEG_STATUS_ERROR;
}


/**
 * @fn TEG_STATUS clitok_dados( char *str)
 */
TEG_STATUS clitok_dados( char *str)
{
	int i;

	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	/* atacante */
	if( parser_call( &p ) && p.hay_otro ) {
		g_juego.dados_srcpais = atoi( p.token );
		if( g_juego.dados_srcpais >= PAISES_CANT || g_juego.dados_srcpais < 0 ) {
			g_juego.dados_srcpais = -1;
			goto error;
		}
	}

	for(i=0;i<3;i++) {
		if( parser_call( &p ) && p.hay_otro ) {
			g_juego.dados_src[i] = atoi( p.token );
		} else goto error;
	}

	/* defensor */
	if( parser_call( &p ) && p.hay_otro ) {
		g_juego.dados_dstpais = atoi( p.token );
		if( g_juego.dados_dstpais >= PAISES_CANT || g_juego.dados_dstpais < 0 ) {
			g_juego.dados_dstpais = -1;
			goto error;
		}
	}

	for(i=0;i<2;i++) {
		if( parser_call( &p ) && p.hay_otro ) {
			g_juego.dados_dst[i] = atoi( p.token );
		} else goto error;
	}

	if( parser_call( &p ) && !p.hay_otro ) {
		g_juego.dados_dst[2] = atoi( p.token );
	} else goto error;

	textmsg(M_INF,_("Dices: %s: %d %d %d vs. %s: %d %d %d")
			,g_paises[g_juego.dados_srcpais].nombre
			,g_juego.dados_src[0]
			,g_juego.dados_src[1]
			,g_juego.dados_src[2]
			,g_paises[g_juego.dados_dstpais].nombre
			,g_juego.dados_dst[0]
			,g_juego.dados_dst[1]
			,g_juego.dados_dst[2] );

	gui_dados();

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_dados()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_ataque( char *str)
 * avisa que 'src' esta atacando a 'dst'
 */
TEG_STATUS clitok_ataque( char *str)
{
	int src,dst;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	PJUGADOR pJsrc, pJdst;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		src = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		dst = atoi( p.token );
	} else goto error;

	if( jugador_whois( g_paises[src].numjug, &pJsrc ) != TEG_STATUS_SUCCESS )
		goto error;

	if( jugador_whois( g_paises[dst].numjug, &pJdst ) != TEG_STATUS_SUCCESS )
		goto error;

	if( src<0 || src >= PAISES_CANT || dst <0 || dst >= PAISES_CANT )
		goto error;

	if( g_paises[src].numjug == WHOAMI() ) {
		ataque_reset();
	} else {
		ataque_show( src, dst );
	}

	textmsg(M_INF,_("%s(%s) is attacking %s(%s)"),g_paises[src].nombre, _(g_colores[pJsrc->color])
			,g_paises[dst].nombre, _(g_colores[pJdst->color]) );

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_ataque()");
	return TEG_STATUS_ERROR;
}


/**
 * @fn TEG_STATUS clitok_turno( char *str)
 */
TEG_STATUS clitok_turno( char *str)
{
	int numjug;
	PJUGADOR j;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		numjug = atoi( p.token );
	} else goto error;

	if( jugador_whois( numjug, &j) != TEG_STATUS_SUCCESS)
		goto error;

	ataque_unshow();
	out_paises();

	if( numjug == g_juego.numjug ) {
		ESTADO_SET(JUG_ESTADO_ATAQUE);
		/* cosas a hacer cuando yo comienzo un nuevo turno */
		reagrupe_bigreset();
		ataque_init();
		textmsg(M_INF,_("Its your turn to attack!!"));
		gui_turno();
	} else  {
		/* No es mi turno, entonces yo tengo que estar en idle */
		textmsg(M_IMP,_("Player %s(%s) has the turn to attack!"),
				j->nombre,
				_(g_colores[j->color]) );
		ESTADO_SET(JUG_ESTADO_IDLE);
	}

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_turno()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_fichas( char *str)
 * Avisa que alguien esta poniendo fichas, y la cantidad que tiene que poner
 */
TEG_STATUS clitok_fichas( char *str)
{
	int numjug;
	int cant;
	PJUGADOR j;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		numjug = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		cant = atoi( p.token );
	} else goto error;

	if( jugador_whois( numjug, &j) != TEG_STATUS_SUCCESS)
		goto error;

	out_paises();

	if( numjug == g_juego.numjug ) {
		ESTADO_SET(JUG_ESTADO_FICHAS);
		fichas_init( cant, 0 );
		gui_fichas(cant,0);
	} else {
		textmsg(M_INF,_("Player %s(%s) is placing %d armies for 1st time"),
				j->nombre,
				_(g_colores[j->color]),
				cant);
	}

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_fichas()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_fichas2( char *str)
 * Avisa que alguien esta poniendo fichas2 y la cantidad que hay que poner
 */
TEG_STATUS clitok_fichas2( char *str)
{
	int numjug;
	int cant;
	PJUGADOR j;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		numjug = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		cant = atoi( p.token );
	} else goto error;

	if( jugador_whois( numjug, &j) != TEG_STATUS_SUCCESS)
		goto error;

	out_paises();

	if( numjug == g_juego.numjug ) {
		ESTADO_SET(JUG_ESTADO_FICHAS2);
		fichas_init( cant, 0 );
		gui_fichas(cant,0);
	} else {
		textmsg(M_INF,_("Player %s(%s) is placing %d armies for 2nd time"),
				j->nombre,
				_(g_colores[j->color]),
				cant);
	}

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_fichas2()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_fichasc( char *str)
 * Se encarga de entender el mensaje FICHASC
 * @param str string que contiene los datos
 * @return SUCCESS si esta bien construido el str
 */
TEG_STATUS clitok_fichasc( char *str)
{
	int numjug;
	int cant,tot_cant;
	unsigned long conts;
	PJUGADOR j;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		numjug = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		conts = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		cant = atoi( p.token );
	} else goto error;

	if( jugador_whois( numjug, &j) != TEG_STATUS_SUCCESS)
		goto error;

	ataque_unshow();

	tot_cant = cont_tot( conts ) + cant;

	out_paises();

	if( numjug == g_juego.numjug ) {
		ESTADO_SET(JUG_ESTADO_FICHASC);
		fichas_init( tot_cant, conts );
		gui_fichas(cant,conts);
	} else {
		textmsg(M_INF,_("Player %s(%s) is placing %d armies"),
				j->nombre,
				_(g_colores[j->color]),
				cant);
	}

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_fichasc()");
	return TEG_STATUS_ERROR;
}


/**
 * @fn TEG_STATUS clitok_paises( char *str)
 * me dice los paises que tiene cierto jugador
 */
TEG_STATUS clitok_paises( char *str)
{
	int numjug;
	PJUGADOR j;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ '/', '/', '/' };


	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro )
		numjug = atoi( p.token );
	else 
		goto error;

	if( jugador_whois( numjug, &j) == TEG_STATUS_SUCCESS)
		return aux_paises( numjug, p.data );
error:
	textmsg(M_ERR,"Error in clitok_paises()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_playerid( char *str)
 * Me dice el player number y los colores disponibles
 */
TEG_STATUS clitok_playerid( char *str)
{
	char c[TEG_MAX_PLAYERS];
	PARSER p;
	int i;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		strncpy( g_juego.myname, p.token, sizeof(g_juego.myname)-1);
		g_juego.myname[sizeof(g_juego.myname)-1]=0;
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		g_juego.numjug = atoi( p.token );
	} else goto error;

	for(i=0;i<TEG_MAX_PLAYERS-1;i++ ) {

		if( parser_call( &p ) && p.hay_otro ) {
			c[i] = atoi( p.token );	
		} else goto error;
	}

	if( parser_call( &p ) && !p.hay_otro ) {
		c[i] = atoi( p.token );	
	} else goto error;


	ESTADO_SET(JUG_ESTADO_CONNECTED);

	out_status();
	if( g_juego.observer )
		out_paises();

	gui_connected( c );

	textmsg( M_IMP,_("I'm player number:%d"),g_juego.numjug );
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_playerid()");
	return TEG_STATUS_ERROR;
}


TEG_STATUS clitok_reconnect( char *str)
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		strncpy( g_juego.myname, p.token, sizeof(g_juego.myname)-1);
		g_juego.myname[sizeof(g_juego.myname)-1]=0;
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		g_juego.numjug = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		g_juego.mycolor  = atoi( p.token );	
	} else goto error;


	ESTADO_SET(JUG_ESTADO_IDLE);

	out_status();
	out_paises();
	out_enum_cards();

	gui_reconnected();

	textmsg( M_IMP,_("Successful reconnection. I'm player number:%d"),g_juego.numjug );
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_reconnect()");
	return TEG_STATUS_ERROR;
}


/**
 * @fn TEG_STATUS clitok_newplayer( char *str)
 * Un nuevo jugador entro
 */
TEG_STATUS clitok_newplayer( char *str)
{
	char name[PLAYERNAME_MAX_LEN];
	int color,numjug;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	JUGADOR j;
	PJUGADOR pJ;

	if( strlen(str)==0 )
		goto error;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( parser_call( &p ) && p.hay_otro ) {
		strncpy( name, p.token, sizeof(name)-1 );
		name[sizeof(name)-1]=0;
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		numjug = atoi( p.token );		
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		color = atoi( p.token );
	} else goto error;

	if( jugador_whois( numjug, &pJ ) != TEG_STATUS_SUCCESS ) {
		memset(&j,0,sizeof(j));
		j.color = color;
		j.numjug = numjug;
		strncpy(j.nombre,name,sizeof(j.nombre)-1);
		j.nombre[sizeof(j.nombre)-1]=0;
		jugador_ins(&j);
	} else
		pJ->color =  color;

	if( numjug == WHOAMI() ) {
		g_juego.mycolor = color;
		ESTADO_SET( JUG_ESTADO_HABILITADO );
		textmsg( M_IMP,_("My color is: %s"),_(g_colores[color]) );
	} else {
		textmsg(M_IMP,_("Player[%d] '%s' is connected with color %s"),numjug,name,_(g_colores[color]));
	}
	gui_habilitado( numjug );

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_newplayer()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_message( char *str)
 * Me enviaron un mensaje
 */
TEG_STATUS clitok_message( char *str)
{
	char name[PLAYERNAME_MAX_LEN];
	int numjug;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };

	if( strlen(str) == 0 )
		goto error;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( parser_call( &p ) && p.hay_otro ) {
		strncpy( name, p.token, sizeof(name)-1);
		name[sizeof(name)-1]=0;
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		numjug = atoi( p.token );		
	} else goto error;

	/* I dont care if there is one more or not */

	if( g_juego.msg_show & M_MSG ) {
		gui_textplayermsg(name,numjug,p.data);
	}
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_message()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_rem( char *str)
 * Ignorar. Usado para enviar help en ascii
 */
TEG_STATUS clitok_rem( char *str)
{
	if(strlen(str)>0)
		textmsg( M_IMP,str );
	return TEG_STATUS_SUCCESS;
}

/**
 * @fn TEG_STATUS clitok_status( char *str)
 * Muestra el estado de todos los jugadores
 */
TEG_STATUS clitok_status( char *str)
{
	JUGADOR j,*j_tmp;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ '/', '/', '/' };

	int i;

	jugador_flush();

	if( strlen(str)==0 )
		goto ok;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;


	do {
		if( (i=parser_call( &p )) ) {
			if( aux_status( &j, p.token ) != TEG_STATUS_SUCCESS )
				goto error;

			if( jugador_whois( j.numjug, &j_tmp ) == TEG_STATUS_SUCCESS )
				jugador_update( &j );
			else
				jugador_ins( &j );
		}
	} while( i && p.hay_otro);
ok:
	gui_status();
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_status()");
	return TEG_STATUS_PARSEERROR;
}


TEG_STATUS clitok_scores( char *str)
{
	PSCORES pS;
	SCORES score;
	PARSER p;
	DELIM igualador = DELIM_NULL;
	DELIM separador={ '\\', '\\', '\\' };

	int i;

	if( strlen(str)==0 )
		goto ok;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	scores_flush();

	do {
		if( (i=parser_call( &p )) ) {
			if( aux_scores( &score, p.token ) != TEG_STATUS_SUCCESS )
				goto error;

			pS = malloc( sizeof(*pS));
			if( ! pS )
				goto error;

			*pS = score;
			scores_insert_score( pS );
		}
	} while( i && p.hay_otro);

ok:
	gui_scores();
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_scores()");
	return TEG_STATUS_PARSEERROR;
}



/**
 * @fn TEG_STATUS clitok_start(char *str)
 * Avisa que empezo el juego
 */
TEG_STATUS clitok_start(char *str)
{
	JUGADOR j;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ '/', '/', '/' };
	int i;

	if( strlen(str)==0 )
		goto error;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	jugador_flush();
	do {
		if( (i=parser_call( &p )) ) {
			if( aux_status( &j, p.token ) != TEG_STATUS_SUCCESS )
				goto error;

			jugador_ins( &j );
		}
	} while( i && p.hay_otro);

	ESTADO_SET(JUG_ESTADO_START);

	out_paises();
	gui_start();
	return TEG_STATUS_SUCCESS;

error:
	textmsg(M_ERR,"Error in clitok_start()");
	return TEG_STATUS_ERROR;
}


TEG_STATUS clitok_enum_cards( char *str )
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int country, used;
	PLIST_ENTRY ltmp;

	g_juego.tarjetas_cant = 0;

	while( ! IsListEmpty( &g_juego.tarjetas_list ) )
		ltmp = RemoveHeadList( &g_juego.tarjetas_list );

	if(  ! str || strlen(str) == 0 )
		goto ok;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	do {
		if( parser_call( &p ) ) {
			country = atoi( p.token );
			used = atoi( p.value );
		} else 
			goto error;

		if( country < 0 || country >= PAISES_CANT )
			goto error;

		InsertTailList( &g_juego.tarjetas_list, (PLIST_ENTRY) &g_paises[ country ].tarjeta );
		g_juego.tarjetas_cant++;

		if( used ) tarjeta_usar( &g_paises[ country ].tarjeta );
		g_paises[ country ].tarjeta.numjug = WHOAMI();

	} while ( p.hay_otro );

ok:
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_enum_cards()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_canje(char *str)
 * Alguien realizo un canje y pude ser yo
 */
TEG_STATUS clitok_canje(char *str)
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int p1,p2,p3;
	int numjug,cant;
	PJUGADOR pJ;

	if( strlen(str)==0 )
		goto error;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( parser_call( &p ) && p.hay_otro ) {
		numjug = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		cant = atoi( p.token );		
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		p1 = atoi( p.token );		
	} else goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		p2 = atoi( p.token );		
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		p3 = atoi( p.token );		
	} else goto error;

	if( jugador_whois( numjug, &pJ) != TEG_STATUS_SUCCESS)
		goto error;

	if( numjug == WHOAMI() ) {
		PLIST_ENTRY pL = g_juego.tarjetas_list.Flink;

		while( !IsListEmpty( &g_juego.tarjetas_list ) && (pL != &g_juego.tarjetas_list )) {
			PPAIS pP;
			PTARJETA pT = (PTARJETA) pL;
			pP = (PPAIS ) PAIS_FROM_TARJETA( pT );

			if( pP->id == p1 || pP->id == p2 || pP->id == p3 ) {
				PLIST_ENTRY l;

				g_paises[ pP->id ].tarjeta.numjug = -1;
				l = RemoveHeadList( pL->Blink );
				g_juego.tarjetas_cant--;

			}
			pL = LIST_NEXT( pL );
		}

		fichas_add_wanted( cant );
		textmsg( M_IMP,_("Exchanged approved. Now you can place %d more armies!"),cant);
		gui_canje(cant,p1,p2,p3);
	} else {
		textmsg(M_IMP,_("Player %s(%s) exchanged 3 cards for %d armies"),
				pJ->nombre,
				_(g_colores[pJ->color]),
				cant);
	}

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_tarjeta()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_modalidad(char *str)
 * Dice con que reglas se va a jugar.
 */
TEG_STATUS clitok_modalidad(char *str)
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int objetivos,reglas;

	if( strlen(str)==0 )
		goto error;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( parser_call( &p ) && p.hay_otro ) {
		objetivos = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		reglas = atoi( p.token );		
	} else goto error;

	g_juego.reglas = reglas ;

	out_objetivos();

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_tarjeta()");
	return TEG_STATUS_ERROR;
}
/**
 * @fn TEG_STATUS clitok_objetivo(char *str)
 * Dice con que reglas se va a jugar.
 */
TEG_STATUS clitok_objetivo(char *str)
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int objetivo;

	if( strlen(str)==0 )
		goto error;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( parser_call( &p ) && !p.hay_otro ) {
		objetivo = atoi( p.token );
	} else goto error;

	if( objetivo < 0 || objetivo >= objetivos_cant() )
		goto error;

	g_juego.objetivo = objetivo;
	gui_objetivo();
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_objetivo()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_tarjeta(char *str)
 * I'm receiving the card I've requested after finishing my turn
 * @param str which card and if the server placed two armies there for me
 */
TEG_STATUS clitok_tarjeta(char *str)
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int pais,used;

	if( strlen(str)==0 )
		goto error;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;


	if( parser_call( &p ) && p.hay_otro ) {
		pais = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		used = atoi( p.token );		
	} else goto error;

	if( pais < 0 || pais >= PAISES_CANT )
		goto error;

	ESTADO_SET(JUG_ESTADO_TARJETA);

	InsertTailList( &g_juego.tarjetas_list, (PLIST_ENTRY) &g_paises[ pais ].tarjeta );
	g_juego.tarjetas_cant++;

	if( used ) tarjeta_usar( &g_paises[ pais ].tarjeta );
	g_paises[ pais ].tarjeta.numjug = WHOAMI();

	if( used ) {
		textmsg(M_IMP,_("You received card: '%s' and 2 armies where placed there"),g_paises[pais].nombre);
	} else {
		textmsg(M_IMP,_("You received card: '%s'"),g_paises[pais].nombre);
	}

	gui_tarjeta( pais );
	return TEG_STATUS_SUCCESS;

error:
	textmsg(M_ERR,"Error in clitok_tarjeta()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_pversion( char *str)
 * Servers's Protocol version. HIVER MUST be equal, otherwise wont work 
 */
TEG_STATUS clitok_pversion( char *str)
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int hi,lo;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( strlen(str)==0 )
		goto error;

	if( parser_call( &p ) && p.hay_otro ) {
		hi = atoi( p.token );
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		lo = atoi( p.token );
	} else goto error;

	if( hi != PROTOCOL_HIVER ) {
		textmsg(M_ERR,_("Aborting: Different protocols version. Server:%d Client:%d"),hi,PROTOCOL_HIVER);
		desconectar();
		return TEG_STATUS_ERROR;
	}

	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_pversion()");
	return TEG_STATUS_ERROR;
}

/**
 * @fn TEG_STATUS clitok_sversion( char *str)
 * Servers version
 */
TEG_STATUS clitok_sversion( char *str)
{
	if( strlen(str)==0 )
		goto error;

	textmsg(M_ALL,"%s",str);
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_pversion()");
	return TEG_STATUS_ERROR;
}


/**
 * @fn TEG_STATUS clitok_ggz( char *str)
 */
#ifdef WITH_GGZ
TEG_STATUS clitok_ggz( char *str)
{
	if( !g_juego.with_ggz )
		goto error;

	out_pversion();
	out_id();
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_ggz()");
	return TEG_STATUS_ERROR;
}
#endif /* WITH_GGZ */



/*
 *	codigo de interpretacion
 */
TEG_STATUS client_lookup( int fd, PARSER *p )
{
	int i;

	for(i = 0; i < NRCLITOKENS; i++) {
		if(strcasecmp( p->token, tokens[i].label )==0 ){
			if (tokens[i].func)
				return( (tokens[i].func)(p->value));
			return TEG_STATUS_TOKENNULL;
		}
	}
	textmsg( M_ERR, _("Token '%s' not found"),p->token);
	return TEG_STATUS_TOKENNOTFOUND;
}

/**
 * @fn TEG_STATUS client_recv( int fd )
 * lee del fd los datos para luego parsearlos
 */
TEG_STATUS client_recv( int fd )
{
	int i,j;
	PARSER p;
	char str[PROT_MAX_LEN];
	DELIM igualador={ '=', '=', '=' };
	DELIM separador={ ';', ';', ';' };

	p.igualador = &igualador;
	p.separador = &separador;

	memset(str,0,sizeof(str));
	j=net_readline( fd, str, PROT_MAX_LEN );

	if( j<1 ) {
		desconectar();
		return TEG_STATUS_CONNCLOSED;
	}

	p.data = str;

	do {
		if( (i=parser_call( &p )) ) {
			if( client_lookup( fd,&p ) == TEG_STATUS_CONNCLOSED ) {
				return TEG_STATUS_CONNCLOSED;
			}
		}
	} while( i && p.hay_otro);

	return TEG_STATUS_SUCCESS;
}