-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgpiInfo.c
1173 lines (974 loc) · 28.5 KB
/
gpiInfo.c
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
///////////////////////////////////////////////////////////////////////////////
// File: gpiInfo.c
// SDK: GameSpy Presence and Messaging SDK
//
// Copyright (c) 2012 GameSpy Technology & IGN Entertainment, Inc. All rights
// reserved. This software is made available only pursuant to certain license
// terms offered by IGN or its subsidiary GameSpy Industries, Inc. Unlicensed
// use or use in a manner not expressly authorized by IGN or GameSpy Technology
// is prohibited.
//INCLUDES
#include "gpi.h"
//FUNCTIONS
static GPIBool
gpiIsValidDate(
int day,
int month,
int year
)
{
// Check for a blank.
if((day == 0) && (month == 0) && (year == 0))
return GPITrue;
// Check for negatives.
if((day < 0) || (month < 0) || (year < 0))
return GPIFalse;
// Validate the day of the month.
switch(month)
{
// No month.
case 0:
// Can't specify a day without a month.
if(day != 0)
return GPIFalse;
break;
// 31-day month.
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(day > 31)
return GPIFalse;
break;
// 30-day month.
case 4:
case 6:
case 9:
case 11:
if(day > 30)
return GPIFalse;
break;
// 28/29-day month.
case 2:
// Leap year?
if((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0))
{
if(day > 29)
return GPIFalse;
}
else
{
if(day > 28)
return GPIFalse;
}
break;
// Invalid month.
default:
return GPIFalse;
}
// Check that the date is in the valid range:
// 01.01.1900 - 06.06.2079
if(year < 1900)
return GPIFalse;
if(year > 2079)
return GPIFalse;
if(year == 2079)
{
if(month > 6)
return GPIFalse;
if((month == 6) && (day > 6))
return GPIFalse;
}
return GPITrue;
}
static GPResult
gpiDateToInt(
GPConnection * connection,
int * date,
int day,
int month,
int year
)
{
int temp;
// Pack the day/month/year into an int.
// 31-22: day
// 23-16: month
// 15-00: year
// Error check.
GS_ASSERT(gpiIsValidDate(day, month, year));
if(!gpiIsValidDate(day, month, year))
Error(connection, GP_PARAMETER_ERROR, "Invalid date.");
// Pack!
temp = 0;
temp |= (day << 24);
temp |= (month << 16);
temp |= year;
// Set it.
*date = temp;
return GP_NO_ERROR;
}
static GPResult
gpiIntToDate(
GPConnection * connection,
int date,
int * day,
int * month,
int * year
)
{
int d;
int m;
int y;
// Unpack the int into a day/month/year.
// 31-22: day
// 23-16: month
// 15-00: year
// Split up the date.
d = ((date >> 24) & 0xFF);
m = ((date >> 16) & 0xFF);
y = (date & 0xFFFF);
// Error check.
GS_ASSERT(gpiIsValidDate(d, m, y));
if(!gpiIsValidDate(d, m, y))
Error(connection, GP_PARAMETER_ERROR, "Invalid date.");
// It's all good.
*day = d;
*month = m;
*year = y;
return GP_NO_ERROR;
}
void
gpiInfoCacheToArg(
const GPIInfoCache * cache,
GPGetInfoResponseArg * arg
)
{
#ifndef GSI_UNICODE
// Copy....
if(cache->nick)
strzcpy(arg->nick, cache->nick, GP_NICK_LEN);
else
arg->nick[0] = '\0';
if(cache->uniquenick)
strzcpy(arg->uniquenick, cache->uniquenick, GP_UNIQUENICK_LEN);
else
arg->uniquenick[0] = '\0';
if(cache->email)
strzcpy(arg->email, cache->email, GP_EMAIL_LEN);
else
arg->email[0] = '\0';
if(cache->firstname)
strzcpy(arg->firstname, cache->firstname, GP_FIRSTNAME_LEN);
else
arg->firstname[0] = '\0';
if(cache->lastname)
strzcpy(arg->lastname, cache->lastname, GP_LASTNAME_LEN);
else
arg->lastname[0] = '\0';
if(cache->homepage)
strzcpy(arg->homepage, cache->homepage, GP_HOMEPAGE_LEN);
else
arg->homepage[0] = '\0';
arg->icquin = cache->icquin;
strzcpy(arg->zipcode, cache->zipcode, GP_ZIPCODE_LEN);
strzcpy(arg->countrycode, cache->countrycode, GP_COUNTRYCODE_LEN);
arg->longitude = cache->longitude;
arg->latitude = cache->latitude;
strzcpy(arg->place, cache->place, GP_PLACE_LEN);
arg->birthday = cache->birthday;
arg->birthmonth = cache->birthmonth;
arg->birthyear = cache->birthyear;
arg->sex = (GPEnum)cache->sex;
arg->publicmask = (GPEnum)cache->publicmask;
if(cache->aimname)
strzcpy(arg->aimname, cache->aimname, GP_AIMNAME_LEN);
else
arg->aimname[0] = '\0';
#else
// Copy....
if(cache->nick)
UTF8ToUCSStringLen(cache->nick, arg->nick, GP_NICK_LEN);
else
arg->nick[0] = '\0';
if(cache->uniquenick)
UTF8ToUCSStringLen(cache->uniquenick, arg->uniquenick, GP_UNIQUENICK_LEN);
else
arg->uniquenick[0] = '\0';
if(cache->email)
UTF8ToUCSStringLen(cache->email, arg->email, GP_EMAIL_LEN);
else
arg->email[0] = '\0';
if(cache->firstname)
UTF8ToUCSStringLen(cache->firstname, arg->firstname, GP_FIRSTNAME_LEN);
else
arg->firstname[0] = '\0';
if(cache->lastname)
UTF8ToUCSStringLen(cache->lastname, arg->lastname, GP_LASTNAME_LEN);
else
arg->lastname[0] = '\0';
if(cache->homepage)
UTF8ToUCSStringLen(cache->homepage, arg->homepage, GP_HOMEPAGE_LEN);
else
arg->homepage[0] = '\0';
UTF8ToUCSStringLen(cache->zipcode, arg->zipcode, GP_ZIPCODE_LEN);
UTF8ToUCSStringLen(cache->countrycode, arg->countrycode, GP_COUNTRYCODE_LEN);
if(cache->place)
UTF8ToUCSStringLen(cache->place, arg->place, GP_PLACE_LEN);
else
arg->place[0] = '\0';
if(cache->aimname)
UTF8ToUCSStringLen(cache->aimname, arg->aimname, GP_AIMNAME_LEN);
else
arg->aimname[0] = '\0';
#endif
// Non string members
arg->icquin = cache->icquin;
arg->longitude = cache->longitude;
arg->latitude = cache->latitude;
arg->birthday = cache->birthday;
arg->birthmonth = cache->birthmonth;
arg->birthyear = cache->birthyear;
arg->sex = (GPEnum)cache->sex;
arg->publicmask = (GPEnum)cache->publicmask;
arg->pic = cache->pic;
arg->occupationid = cache->occupationid;
arg->industryid = cache->industryid;
arg->incomeid = cache->incomeid;
arg->marriedid = cache->marriedid;
arg->childcount = cache->childcount;
arg->interests1 = cache->interests1;
arg->ownership1 = cache->ownership1;
arg->conntypeid = cache->conntypeid;
}
GPResult
gpiProcessGetInfo(
GPConnection * connection,
GPIOperation * operation,
const char * input
)
{
GPIInfoCache infoCache;
char buffer[64];
int profileid;
GPIProfile * profile;
GPIConnection * iconnection = (GPIConnection*)*connection;
GPICallback callback;
GPIPeer * peer;
char nick[GP_NICK_LEN];
char uniquenick[GP_UNIQUENICK_LEN];
char email[GP_EMAIL_LEN];
char firstname[GP_FIRSTNAME_LEN];
char lastname[GP_LASTNAME_LEN];
char homepage[GP_HOMEPAGE_LEN];
char aimname[GP_AIMNAME_LEN];
GPIBool saveSig;
// Check for an error.
if(gpiCheckForError(connection, input, GPITrue))
return GP_SERVER_ERROR;
// This should be \pi\.
if(strncmp(input, "\\pi\\", 4) != 0)
CallbackFatalError(connection, GP_NETWORK_ERROR, GP_PARSE, "Unexpected data was received from the server.");
// Get the profile id.
if(!gpiValueForKey(input, "\\profileid\\", buffer, sizeof(buffer)))
CallbackFatalError(connection, GP_NETWORK_ERROR, GP_PARSE, "Unexpected data was received from the server.");
profileid = atoi(buffer);
GS_ASSERT(profileid > 0);
// Get the profile - we might not have a profile object.
gpiGetProfile(connection, (GPProfile)profileid, &profile);
// Setup the info cache.
memset(&infoCache, 0, sizeof(GPIInfoCache));
infoCache.nick = nick;
infoCache.uniquenick = uniquenick;
infoCache.email = email;
infoCache.firstname = firstname;
infoCache.lastname = lastname;
infoCache.homepage = homepage;
infoCache.aimname = aimname;
// Parse the info.
if(!gpiValueForKey(input, "\\nick\\", infoCache.nick, GP_NICK_LEN))
infoCache.nick[0] = '\0';
if(!gpiValueForKey(input, "\\uniquenick\\", infoCache.uniquenick, GP_UNIQUENICK_LEN))
infoCache.uniquenick[0] = '\0';
if(!gpiValueForKey(input, "\\email\\", infoCache.email, GP_EMAIL_LEN))
infoCache.email[0] = '\0';
if(!gpiValueForKey(input, "\\firstname\\", infoCache.firstname, GP_FIRSTNAME_LEN))
infoCache.firstname[0] = '\0';
if(!gpiValueForKey(input, "\\lastname\\", infoCache.lastname, GP_LASTNAME_LEN))
infoCache.lastname[0] = '\0';
if(!gpiValueForKey(input, "\\icquin\\", buffer, sizeof(buffer)))
infoCache.icquin = -1;
else
infoCache.icquin = atoi(buffer);
if(!gpiValueForKey(input, "\\homepage\\", infoCache.homepage, GP_HOMEPAGE_LEN))
infoCache.homepage[0] = '\0';
if(!gpiValueForKey(input, "\\zipcode\\", infoCache.zipcode, sizeof(infoCache.zipcode)))
infoCache.zipcode[0] = '\0';
if(!gpiValueForKey(input, "\\countrycode\\", infoCache.countrycode, sizeof(infoCache.countrycode)))
infoCache.countrycode[0] = '\0';
if(!gpiValueForKey(input, "\\lon\\", buffer, sizeof(buffer)))
infoCache.longitude = 0;
else
infoCache.longitude = (float)atof(buffer);
if(!gpiValueForKey(input, "\\lat\\", buffer, sizeof(buffer)))
infoCache.latitude = 0;
else
infoCache.latitude = (float)atof(buffer);
if(!gpiValueForKey(input, "\\loc\\", infoCache.place, GP_PLACE_LEN))
infoCache.place[0] = '\0';
if(!gpiValueForKey(input, "\\birthday\\", buffer, sizeof(buffer)))
{
infoCache.birthday = 0;
infoCache.birthmonth = 0;
infoCache.birthyear = 0;
}
else
{
CHECK_RESULT(gpiIntToDate(connection, atoi(buffer), &infoCache.birthday, &infoCache.birthmonth, &infoCache.birthyear));
}
if(!gpiValueForKey(input, "\\sex\\", buffer, sizeof(buffer)))
infoCache.sex = GP_PAT;
else if(buffer[0] == '0')
infoCache.sex = GP_MALE;
else if(buffer[0] == '1')
infoCache.sex = GP_FEMALE;
else
infoCache.sex = GP_PAT;
if(!gpiValueForKey(input, "\\pmask\\", buffer, sizeof(buffer)))
infoCache.publicmask = 0xFFFFFFFF;
else
infoCache.publicmask = atoi(buffer);
if(!gpiValueForKey(input, "\\aim\\", infoCache.aimname, GP_AIMNAME_LEN))
infoCache.aimname[0] = '\0';
if(!gpiValueForKey(input, "\\pic\\", buffer, sizeof(buffer)))
infoCache.pic = 0;
else
infoCache.pic = atoi(buffer);
if(!gpiValueForKey(input, "\\occ\\", buffer, sizeof(buffer)))
infoCache.occupationid = 0;
else
infoCache.occupationid = atoi(buffer);
if(!gpiValueForKey(input, "\\ind\\", buffer, sizeof(buffer)))
infoCache.industryid = 0;
else
infoCache.industryid = atoi(buffer);
if(!gpiValueForKey(input, "\\inc\\", buffer, sizeof(buffer)))
infoCache.incomeid = 0;
else
infoCache.incomeid = atoi(buffer);
if(!gpiValueForKey(input, "\\mar\\", buffer, sizeof(buffer)))
infoCache.marriedid = 0;
else
infoCache.marriedid = atoi(buffer);
if(!gpiValueForKey(input, "\\chc\\", buffer, sizeof(buffer)))
infoCache.childcount = 0;
else
infoCache.childcount = atoi(buffer);
if(!gpiValueForKey(input, "\\i1\\", buffer, sizeof(buffer)))
infoCache.interests1 = 0;
else
infoCache.interests1 = atoi(buffer);
if(!gpiValueForKey(input, "\\o1\\", buffer, sizeof(buffer)))
infoCache.ownership1 = 0;
else
infoCache.ownership1 = atoi(buffer);
if(!gpiValueForKey(input, "\\conn\\", buffer, sizeof(buffer)))
infoCache.conntypeid = 0;
else
infoCache.conntypeid = atoi(buffer);
// Get the peer sig.
if(!gpiValueForKey(input, "\\sig\\", buffer, sizeof(buffer)))
CallbackFatalError(connection, GP_NETWORK_ERROR, GP_PARSE, "Unexpected data was received from the server.");
saveSig = iconnection->infoCaching;
// Is there a pending peer connection looking for a sig?
for(peer = iconnection->peerList ; peer != NULL ; peer = peer->pnext)
{
// Is it the same profile?
if(peer->profile == profileid)
{
// Is it getting the sig?
if(peer->state == GPI_PEER_GETTING_SIG)
{
// We need to make sure there's an actual profile object.
if(!profile)
profile = gpiProfileListAdd(connection, profileid);
// It got it.
peer->state = GPI_PEER_GOT_SIG;
saveSig = GPITrue;
}
}
}
// Cache info?
if(!profile && iconnection->infoCaching)
profile = gpiProfileListAdd(connection, profileid);
// Set the peer sig.
if(saveSig)
{
freeclear(profile->peerSig);
profile->peerSig = goastrdup(buffer);
}
// Caching info?
if(iconnection->infoCaching)
gpiSetInfoCache(connection, profile, &infoCache);
// Call the callback.
callback = operation->callback;
if(callback.callback != NULL)
{
GPGetInfoResponseArg * arg;
arg = (GPGetInfoResponseArg *)gsimalloc(sizeof(GPGetInfoResponseArg));
if(arg == NULL)
Error(connection, GP_MEMORY_ERROR, "Out of memory.");
gpiInfoCacheToArg(&infoCache, arg);
arg->result = GP_NO_ERROR;
arg->profile = (GPProfile)profileid;
CHECK_RESULT(gpiAddCallback(connection, callback, arg, operation, 0));
}
// This operation is complete.
gpiRemoveOperation(connection, operation);
return GP_NO_ERROR;
}
GPResult
gpiAddLocalInfo(
GPConnection * connection,
GPIBuffer * buffer
)
{
GPIConnection * iconnection = (GPIConnection*)*connection;
// Add updatepro info.
if(iconnection->updateproBuffer.len > 0)
{
gpiAppendStringToBuffer(connection, buffer, "\\updatepro\\\\sesskey\\");
gpiAppendIntToBuffer(connection, buffer, iconnection->sessKey);
gpiAppendStringToBuffer(connection, buffer, iconnection->updateproBuffer.buffer);
gpiAppendStringToBuffer(connection, buffer, "\\partnerid\\");
gpiAppendIntToBuffer(connection, buffer, iconnection->partnerID);
gpiAppendStringToBuffer(connection, buffer, "\\final\\");
iconnection->updateproBuffer.len = 0;
}
// Add updateui info.
if(iconnection->updateuiBuffer.len > 0)
{
gpiAppendStringToBuffer(connection, buffer, "\\updateui\\\\sesskey\\");
gpiAppendIntToBuffer(connection, buffer, iconnection->sessKey);
gpiAppendStringToBuffer(connection, buffer, iconnection->updateuiBuffer.buffer);
gpiAppendStringToBuffer(connection, buffer, "\\final\\");
iconnection->updateuiBuffer.len = 0;
}
return GP_NO_ERROR;
}
static GPResult
gpiSendLocalInfo(
GPConnection * connection,
const char * info,
const char * value
)
{
GPIConnection * iconnection = (GPIConnection*)*connection;
CHECK_RESULT(gpiAppendStringToBuffer(connection, &iconnection->updateproBuffer, info));
CHECK_RESULT(gpiAppendStringToBuffer(connection, &iconnection->updateproBuffer, value));
return GP_NO_ERROR;
}
static GPResult
gpiSendUserInfo(
GPConnection * connection,
const char * info,
const char * value
)
{
GPIConnection * iconnection = (GPIConnection*)*connection;
CHECK_RESULT(gpiAppendStringToBuffer(connection, &iconnection->updateuiBuffer, info));
CHECK_RESULT(gpiAppendStringToBuffer(connection, &iconnection->updateuiBuffer, value));
return GP_NO_ERROR;
}
GPResult
gpiSetInfoi(
GPConnection * connection,
GPEnum info,
int value
)
{
char intValue[16];
// Check the info param.
switch(info)
{
case GP_ZIPCODE:
// Error check.
if(value < 0)
Error(connection, GP_PARAMETER_ERROR, "Invalid zipcode.");
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\zipcode\\", intValue));
break;
case GP_SEX:
// Check the sex type.
switch(value)
{
case GP_MALE:
CHECK_RESULT(gpiSendLocalInfo(connection, "\\sex\\", "0"));
break;
case GP_FEMALE:
CHECK_RESULT(gpiSendLocalInfo(connection, "\\sex\\", "1"));
break;
case GP_PAT:
CHECK_RESULT(gpiSendLocalInfo(connection, "\\sex\\", "2"));
break;
default:
Error(connection, GP_PARAMETER_ERROR, "Invalid sex.");
}
break;
case GP_ICQUIN:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\icquin\\", intValue));
break;
case GP_CPUBRANDID:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendUserInfo(connection, "\\cpubrandid\\", intValue));
break;
case GP_CPUSPEED:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendUserInfo(connection, "\\cpuspeed\\", intValue));
break;
case GP_MEMORY:
// Divide by 16.
value /= 16;
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendUserInfo(connection, "\\memory\\", intValue));
break;
case GP_VIDEOCARD1RAM:
// Divide by 4.
value /= 4;
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendUserInfo(connection, "\\videocard1ram\\", intValue));
break;
case GP_VIDEOCARD2RAM:
// Divide by 4.
value /= 4;
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendUserInfo(connection, "\\videocard2ram\\", intValue));
break;
case GP_CONNECTIONID:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendUserInfo(connection, "\\connectionid\\", intValue));
break;
case GP_CONNECTIONSPEED:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendUserInfo(connection, "\\connectionspeed\\", intValue));
break;
case GP_HASNETWORK:
// A boolean.
if(value)
value = 1;
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendUserInfo(connection, "\\hasnetwork\\", intValue));
break;
case GP_PIC:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\pic\\", intValue));
break;
case GP_OCCUPATIONID:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\occ\\", intValue));
break;
case GP_INDUSTRYID:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\ind\\", intValue));
break;
case GP_INCOMEID:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\inc\\", intValue));
break;
case GP_MARRIEDID:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\mar\\", intValue));
break;
case GP_CHILDCOUNT:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\chc\\", intValue));
break;
case GP_INTERESTS1:
// Convert it to a string.
sprintf(intValue,"%d",value);
// Send it to the server.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\i1\\", intValue));
break;
default:
Error(connection, GP_PARAMETER_ERROR, "Invalid info.");
}
return GP_NO_ERROR;
}
GPResult
gpiSetInfos(
GPConnection * connection,
GPEnum info,
const char * value
)
{
GPIConnection * iconnection = (GPIConnection*)*connection;
char buffer[256];
char sex;
//password encryption stuff
char passwordenc[GP_PASSWORDENC_LEN];
// Error check.
if(value == NULL)
Error(connection, GP_PARAMETER_ERROR, "Invalid value.");
// Check the info param.
switch(info)
{
case GP_NICK:
if(!value[0])
Error(connection, GP_PARAMETER_ERROR, "Invalid value.");
strzcpy(buffer, value, GP_NICK_LEN);
strzcpy(iconnection->nick, buffer, GP_NICK_LEN);
#ifdef GSI_UNICODE
UTF8ToUCSStringLen(iconnection->nick, iconnection->nick_W, GP_NICK_LEN); // update the UCS2 version
#endif
CHECK_RESULT(gpiSendLocalInfo(connection, "\\nick\\", buffer));
break;
case GP_UNIQUENICK:
if(!value[0])
Error(connection, GP_PARAMETER_ERROR, "Invalid value.");
strzcpy(buffer, value, GP_UNIQUENICK_LEN);
strzcpy(iconnection->uniquenick, buffer, GP_UNIQUENICK_LEN);
#ifdef GSI_UNICODE
UTF8ToUCSStringLen(iconnection->uniquenick, iconnection->uniquenick_W, GP_UNIQUENICK_LEN);
#endif
CHECK_RESULT(gpiSendLocalInfo(connection, "\\uniquenick\\", buffer));
break;
case GP_EMAIL:
if(!value[0])
Error(connection, GP_PARAMETER_ERROR, "Invalid value.");
strzcpy(buffer, value, GP_EMAIL_LEN);
_strlwr(buffer);
strzcpy(iconnection->email, buffer, GP_EMAIL_LEN);
#ifdef GSI_UNICODE
UTF8ToUCSStringLen(iconnection->email, iconnection->email_W, GP_EMAIL_LEN);
#endif
CHECK_RESULT(gpiSendUserInfo(connection, "\\email\\", buffer));
break;
case GP_PASSWORD:
if(!value[0])
Error(connection, GP_PARAMETER_ERROR, "Invalid value.");
strzcpy(buffer, value, GP_PASSWORD_LEN);
strzcpy(iconnection->password, buffer, GP_PASSWORD_LEN);
#ifdef GSI_UNICODE
UTF8ToUCSStringLen(iconnection->password, iconnection->password_W, GP_PASSWORD_LEN);
#endif
gpiEncodeString(iconnection->password, passwordenc);
CHECK_RESULT(gpiSendUserInfo(connection, "\\passwordenc\\", passwordenc));
break;
case GP_FIRSTNAME:
strzcpy(buffer, value, GP_FIRSTNAME_LEN);
CHECK_RESULT(gpiSendLocalInfo(connection, "\\firstname\\", buffer));
break;
case GP_LASTNAME:
strzcpy(buffer, value, GP_LASTNAME_LEN);
CHECK_RESULT(gpiSendLocalInfo(connection, "\\lastname\\", buffer));
break;
case GP_HOMEPAGE:
strzcpy(buffer, value, GP_HOMEPAGE_LEN);
CHECK_RESULT(gpiSendLocalInfo(connection, "\\homepage\\", buffer));
break;
case GP_ZIPCODE:
strzcpy(buffer, value, GP_ZIPCODE_LEN);
CHECK_RESULT(gpiSendLocalInfo(connection, "\\zipcode\\", buffer));
break;
case GP_COUNTRYCODE:
// Error check.
if(strlen(value) != 2)
Error(connection, GP_PARAMETER_ERROR, "Invalid countrycode.");
strzcpy(buffer, value, GP_COUNTRYCODE_LEN);
CHECK_RESULT(gpiSendLocalInfo(connection, "\\countrycode\\", buffer));
break;
case GP_SEX:
sex = (char)toupper(value[0]);
if(sex == 'M')
buffer[0] = '0';
else if(sex == 'F')
buffer[0] = '1';
else
buffer[0] = '2';
buffer[1] = '\0';
CHECK_RESULT(gpiSendLocalInfo(connection, "\\sex\\", buffer));
break;
case GP_ICQUIN:
gsiSafeStrcpyA(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\icquin\\", buffer));
break;
case GP_CPUSPEED:
CHECK_RESULT(gpiSetInfoi(connection, GP_CPUSPEED, atoi(value)));
break;
case GP_MEMORY:
CHECK_RESULT(gpiSetInfoi(connection, GP_MEMORY, atoi(value)));
break;
case GP_VIDEOCARD1STRING:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\videocard1string\\", buffer));
break;
case GP_VIDEOCARD1RAM:
CHECK_RESULT(gpiSetInfoi(connection, GP_VIDEOCARD1RAM, atoi(value)));
break;
case GP_VIDEOCARD2STRING:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\videocard2string\\", buffer));
break;
case GP_VIDEOCARD2RAM:
CHECK_RESULT(gpiSetInfoi(connection, GP_VIDEOCARD2RAM, atoi(value)));
break;
case GP_CONNECTIONSPEED:
CHECK_RESULT(gpiSetInfoi(connection, GP_CONNECTIONSPEED, atoi(value)));
break;
case GP_HASNETWORK:
CHECK_RESULT(gpiSetInfoi(connection, GP_HASNETWORK, atoi(value)));
break;
case GP_OSSTRING:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\osstring\\", buffer));
break;
case GP_AIMNAME:
strzcpy(buffer, value, GP_AIMNAME_LEN);
CHECK_RESULT(gpiSendLocalInfo(connection, "\\aim\\", buffer));
break;
case GP_PIC:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\pic\\", buffer));
break;
case GP_OCCUPATIONID:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\occ\\", buffer));
break;
case GP_INDUSTRYID:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\ind\\", buffer));
break;
case GP_INCOMEID:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\inc\\", buffer));
break;
case GP_MARRIEDID:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\mar\\", buffer));
break;
case GP_CHILDCOUNT:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\chc\\", buffer));
break;
case GP_INTERESTS1:
strzcpy(buffer, value, sizeof(buffer));
CHECK_RESULT(gpiSendLocalInfo(connection, "\\i1\\", buffer));
break;
default:
Error(connection, GP_PARAMETER_ERROR, "Invalid info.");
}
return GP_NO_ERROR;
}
GPResult
gpiSetInfod(
GPConnection * connection,
GPEnum info,
int day,
int month,
int year
)
{
int date;
char intValue[16];
// Birthday is the only date supported.
if(info != GP_BIRTHDAY)
Error(connection, GP_PARAMETER_ERROR, "Invalid info.");
// Convert the date into our internal format.
CHECK_RESULT(gpiDateToInt(connection, &date, day, month, year));
// Convert the int to a string.
sprintf(intValue,"%d",date);
// Send the date.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\birthday\\", intValue));
return GP_NO_ERROR;
}
GPResult
gpiSetInfoMask(
GPConnection * connection,
GPEnum mask
)
{
char buffer[16];
// Convert the mask to a string.
sprintf(buffer,"%d",mask);
// Send it.
CHECK_RESULT(gpiSendLocalInfo(connection, "\\publicmask\\", buffer));
return GP_NO_ERROR;