/
multiplayer.c
1962 lines (1791 loc) · 46.3 KB
/
multiplayer.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
#include <string.h>
#include <time.h>
#include "multiplayer.h"
#include "2d_objects.h"
#include "3d_objects.h"
#include "asc.h"
#include "actors.h"
#include "actor_scripts.h"
#include "books.h"
#include "buddy.h"
#include "buffs.h"
#include "chat.h"
#include "console.h"
#include "dialogues.h"
#include "draw_scene.h"
#include "elwindows.h"
#include "errors.h"
#include "filter.h"
#include "gamewin.h"
#include "global.h"
#include "hud.h"
#include "init.h"
#include "interface.h"
#include "knowledge.h"
#include "lights.h"
#include "loginwin.h"
#include "manufacture.h"
#include "map.h"
#include "new_actors.h"
#include "new_character.h"
#include "particles.h"
#include "pathfinder.h"
#include "questlog.h"
#include "queue.h"
#include "rules.h"
#include "serverpopup.h"
#include "sound.h"
#include "spells.h"
#include "storage.h"
#include "trade.h"
#include "translate.h"
#include "update.h"
#include "weather.h"
#include "counters.h"
#include "special_effects.h"
#include "eye_candy_wrapper.h"
#include "mines.h"
#include "sendvideoinfo.h"
#include "servers.h"
#include "popup.h"
#include "missiles.h"
/* NOTE: This file contains implementations of the following, currently unused, and commented functions:
* Look at the end of the file.
*
* void get_updates();
*/
const char * web_update_address= "http://www.eternal-lands.com/index.php?content=update";
int icon_in_spellbar= -1;
int port= 2000;
unsigned char server_address[60];
TCPsocket my_socket= 0;
SDLNet_SocketSet set= 0;
#define MAX_TCP_BUFFER 8192
Uint8 tcp_in_data[MAX_TCP_BUFFER];
Uint8 tcp_out_data[MAX_TCP_BUFFER];
int tcp_out_loc= 0;
int previously_logged_in= 0;
time_t last_heart_beat;
int always_pathfinding = 0;
char inventory_item_string[300] = {0};
size_t inventory_item_string_id = 0;
char our_name[20];
char our_password[20];
int log_conn_data= 0;
int this_version_is_invalid= 0;
int put_new_data_offset= 0;
Uint8 tcp_cache[256];
Uint32 tcp_cache_len= 0;
Uint32 tcp_cache_time= 0;
//for the client/server sync
int server_time_stamp= 0;
int client_time_stamp= 0;
int client_server_delta_time= 0;
int yourself= -1;
int last_sit= 0;
int last_turn_around = 0;
void move_to (short int x, short int y, int try_pathfinder)
{
Uint8 str[5];
if (try_pathfinder && always_pathfinding)
{
actor *me = get_our_actor();
/* check distance */
if (me && (abs(me->x_tile_pos-x)+abs(me->y_tile_pos-y)) > 2)
/* if path finder fails, try standard move */
if (pf_find_path(x,y))
return;
}
str[0]= MOVE_TO;
*((short *)(str+1))= SDL_SwapLE16 (x);
*((short *)(str+3))= SDL_SwapLE16 (y);
my_tcp_send(my_socket, str, 5);
}
void send_heart_beat()
{
Uint8 command[64];
int len;
last_heart_beat= time(NULL);
command[0]= HEART_BEAT;
len= 1;
#ifdef OLC
len+= olc_heartbeat(command+len);
#endif //OLC
my_tcp_send(my_socket, command, len);
}
int my_tcp_send (TCPsocket my_socket, const Uint8 *str, int len)
{
if(disconnected) {
return 0;
}
if(tcp_out_loc > 0 && tcp_out_loc + len + 2 >= MAX_TCP_BUFFER){
// wouldn't fit, send what we have
my_tcp_flush(my_socket);
}
// LabRat's anti-bagspam code
// Grum: Adapted. Converting every movement to a path caused too much
// trouble. Instead we now check the current actor animation for
// movement.
if ((str[0] == TURN_LEFT || str[0] == TURN_RIGHT) && on_the_move (get_our_actor ()))
return 0;
if (str[0] == DROP_ITEM && on_the_move (get_our_actor ()))
{
// I thought about having a bit of code here that counts attempts, and after say 5,
// announces on #abuse something like "#abuse I attempted to bagspam, but was thwarted,
// please teach me the error of my ways so I refrain from doing so in the future"
/*if((spamcount++)>4)
{
Uint8 badstr[256];
safe_snprintf (badstr, sizeof(badstr), "#abuse I attempted to bagspam %i bags, but was thwarted, please correct me", spamcount);
send_input_text_line (badstr, strlen(badstr));
spamcount = 0; /reset spam count so the #abuse staff don't get swamped..
}*/
// The anti bagspam code in all its glory - don't allow us to drop a bag if following
// a path - I tried coding every DROP_ALL part of the code, but it was longwinded and
// this way, after a couple of hours break, seemed the more logical and straightforward
// solution.
// 1% of the produce from manufacturers may be donated to Labrat for this patch,
// or for the bagspammers, sell the items you were going to spam and give the proceeds
// to a noob on IP :)
//
return 1;
}
//check to see if we have too many packets being sent of the same to reduce server flood
if(len < sizeof (tcp_cache)) // only if it fits
{
if(str[0]==MOVE_TO || str[0]==RUN_TO || str[0]==SIT_DOWN || str[0]==HARVEST || str[0]==MANUFACTURE_THIS || str[0]==CAST_SPELL || str[0]==RESPOND_TO_NPC || str[0]==ATTACK_SOMEONE || str[0]==SEND_PM || str[0]==RAW_TEXT || str[0]==TURN_LEFT || str[0]==TURN_RIGHT)
{
Uint32 time_limit= 600;
if( str[0]==SEND_PM || str[0]==RAW_TEXT)time_limit=1500;
if( str[0]==SIT_DOWN){
if(last_sit+1500>cur_time) return 0;
last_sit= cur_time;
}
if( str[0]==TURN_RIGHT || str[0]==TURN_LEFT )
{
if(last_turn_around + 600 > cur_time) return 0;
last_turn_around = cur_time;
}
//if too close together
if(len == (int)tcp_cache_len && *str == *tcp_cache && cur_time < tcp_cache_time+time_limit){
//and the same packet
if(!memcmp(str, tcp_cache, len)){
//ignore this packet
return 0;
}
}
//turns do not interrupt queued moves
if(tcp_cache[0] == MOVE_TO && (str[0]==TURN_LEFT || str[0]==TURN_RIGHT)) return 0;
//memorize the data we are sending for next time
memcpy(tcp_cache, str, len);
tcp_cache_len= len;
tcp_cache_time= cur_time;
}
}
//update the heartbeat timer
last_heart_beat= time(NULL);
// check to see if the data would fit in the buffer
if(len + 2 < MAX_TCP_BUFFER){
// yes, buffer it for later processing
tcp_out_data[tcp_out_loc]= str[0]; //copy the protocol byte
*((short *)(tcp_out_data+tcp_out_loc+1))= SDL_SwapLE16((Uint16)len);//the data length
// copy the rest of the data
memcpy(&tcp_out_data[tcp_out_loc+3], &str[1], len-1);
// adjust then buffer offset
tcp_out_loc+= len+2;
return(len+2);
} else {
// no, send it as is now
Uint8 new_str[1024]; //should be enough
new_str[0]= str[0]; //copy the protocol byte
*((short *)(new_str+1))= SDL_SwapLE16((Uint16)len);//the data length
// copy the rest of the data
memcpy(&new_str[3], &str[1], len-1);
//for(i=1; i<len; i++) {
// new_str[i+2]= str[i];
//}
#ifdef OLC
return olc_tcp_send(my_socket, new_str, len+2);
#else //OLC
return SDLNet_TCP_Send(my_socket, new_str, len+2);
#endif //OLC
}
// error, should never reach here
return 0;
}
int my_tcp_flush (TCPsocket my_socket)
{
int ret;
if(disconnected || tcp_out_loc == 0) {
return 0;
}
// if we are already sending data, lets see about sending a heartbeat a little bit early
if(last_heart_beat+20 <= time(NULL)){
send_heart_beat();
}
// send all the data in the buffer
#ifdef OLC
ret= olc_tcp_send(my_socket, tcp_out_data, tcp_out_loc);
if(ret > 0){
ret= olc_tcp_flush();
}
#else //OLC
ret= SDLNet_TCP_Send(my_socket, tcp_out_data, tcp_out_loc);
#endif //OLC
// empty the buffer
tcp_out_loc= 0;
tcp_cache[0]=0;
return(ret);
}
void send_version_to_server(IPaddress *ip)
{
Uint8 str[64];
int len;
str[0]= SEND_VERSION;
*((short *)(str+1))= SDL_SwapLE16((short)version_first_digit);
*((short *)(str+3))= SDL_SwapLE16((short)version_second_digit);
str[5]= client_version_major;
str[6]= client_version_minor;
str[7]= client_version_release;
str[8]= client_version_patch;
#ifdef EL_BIG_ENDIAN
// byte swapping needed for Macs despite what the docs say
str[9]= (ip->host >> 24)&0xFF;
str[10]= (ip->host >> 16)&0xFF;
str[11]= (ip->host >> 8)&0xFF;
str[12]= ip->host&0xFF;
str[13]= (ip->port >> 8)&0xFF;
str[14]= ip->port&0xFF;
#else //EL_BIG_ENDIAN
str[9]= ip->host&0xFF;
str[10]= (ip->host >> 8)&0xFF;
str[11]= (ip->host >> 16)&0xFF;
str[12]= (ip->host >> 24)&0xFF;
str[13]= ip->port&0xFF;
str[14]= (ip->port >> 8)&0xFF;
#endif //EL_BIG_ENDIAN
len= 15;
#ifdef OLC
len+= olc_version(str+len);
#endif //OLC
my_tcp_send(my_socket, str, len);
}
void connect_to_server()
{
IPaddress ip;
tcp_out_loc= 0; // clear the tcp output buffer
if(this_version_is_invalid) return;
if(set)
{
SDLNet_FreeSocketSet(set);
set= 0;
}
if(my_socket)
{
SDLNet_TCP_Close(my_socket);
my_socket= 0;
}
//clear the buddy list so we don't get multiple entries
clear_buddy();
LOG_TO_CONSOLE(c_red1,connect_to_server_str);
draw_scene(); // update the screen
set= SDLNet_AllocSocketSet(1);
if(!set)
{
log_error("SDLNet_AllocSocketSet: %s\n", SDLNet_GetError());
#ifdef NEW_SOUND
add_sound_object(get_index_for_sound_type_name("Error"), 0, 0, 1);
#endif // NEW_SOUND
SDLNet_Quit();
SDL_Quit();
exit(4); //most of the time this is a major error, but do what you want.
}
if(SDLNet_ResolveHost(&ip,(char*)server_address,port)==-1)
{
LOG_TO_CONSOLE(c_red2,failed_resolve);
#ifdef NEW_SOUND
add_sound_object(get_index_for_sound_type_name("Disconnected"), 0, 0, 1);
#endif // NEW_SOUND
return;
}
my_socket= SDLNet_TCP_Open(&ip);
if(!my_socket)
{
LOG_TO_CONSOLE(c_red1,failed_connect);
LOG_TO_CONSOLE(c_red1,reconnect_str);
LOG_TO_CONSOLE(c_red1,alt_x_quit);
#ifdef NEW_SOUND
add_sound_object(get_index_for_sound_type_name("Disconnected"), 0, 0, 1);
#endif // NEW_SOUND
return;
}
if(SDLNet_TCP_AddSocket(set,my_socket)==-1)
{
log_error("SDLNet_TCP_AddSocket: %s\n", SDLNet_GetError());
SDLNet_Quit();
SDL_Quit();
exit(2);
}
disconnected= 0;
have_storage_list = 0; //With a reconnect, our cached copy of what's in storage may no longer be accurate
//send the current version to the server
send_version_to_server(&ip);
//ask for the opening screen
if(!previously_logged_in)
{
Uint8 str[1];
str[0]= SEND_OPENING_SCREEN;
my_tcp_send(my_socket, str, 1);
}
else
{
yourself= -1;
you_sit= 0;
destroy_all_actors();
send_login_info();
}
//clear out info
last_heart_beat= time(NULL);
send_heart_beat(); // prime the hearbeat to prevent some stray issues when there is lots of lag
hide_window(trade_win);
#ifdef NEW_SOUND
add_sound_object(get_index_for_sound_type_name("Connected"), 0, 0, 1);
#endif // NEW_SOUND
//BUDDY-FIXME: once server-side offline buddies are supported, the next 4 lines can go
//For the buddy notifications
if(time(NULL) > c_time) {
time(&c_time);//note the current time
}
my_tcp_flush(my_socket); // make sure tcp output buffer is empty
}
void send_login_info()
{
int i,j,len;
unsigned char str[40];
len= strlen(username_str);
//check for the username length
if (len < 3)
{
set_login_error (error_username_length, strlen (error_username_length), 1);
return;
}
//join the username and password, and send them to the server
str[0]= LOG_IN;
if(caps_filter && my_isupper(username_str, len)) my_tolower(username_str);
for(i=0; i<len; i++) str[i+1]= username_str[i];
str[i+1]= ' ';
i++;
len= strlen(password_str);
for(j=0; j<len; j++) str[i+j+1]= password_str[j];
str[i+j+1]= 0;
len = strlen((char*)str);
len++;//send the last 0 too
if(my_tcp_send(my_socket, str, len)<len)
{
//we got a nasty error, log it
}
my_tcp_flush(my_socket); // make sure tcp output buffer is empty
}
void send_new_char(char * user_str, char * pass_str, char skin, char hair, char shirt, char pants, char boots,char head, char type)
{
int i,j,len;
unsigned char str[120];
len= strlen(user_str);
str[0]= CREATE_CHAR;
for(i=0; i<len; i++) str[i+1]= user_str[i];
str[i+1]= ' ';
i++;
len= strlen(pass_str);
for(j=0; j<len; j++) str[i+j+1]= pass_str[j];
str[i+j+1]= 0;
//put the colors and gender
str[i+j+2]= skin;
str[i+j+3]= hair;
str[i+j+4]= shirt;
str[i+j+5]= pants;
str[i+j+6]= boots;
str[i+j+7]= type;
str[i+j+8]= head;
len= i+j+9;
if(my_tcp_send(my_socket,str,len)<len) {
//we got a nasty error, log it
}
my_tcp_flush(my_socket); // make sure tcp output buffer is empty
}
// TEMP LOGAND [5/25/2004]
#ifndef NPC_SAY_OVERTEXT
#define NPC_SAY_OVERTEXT 58
#endif
//---
void process_message_from_server (const Uint8 *in_data, int data_length)
{
Uint8 text_buf[MAX_TCP_BUFFER];
if (data_length <= 2)
{
log_error("CAUTION: Possibly forged packet received.\n");
return;
}
//see what kind of data we got
switch (in_data[PROTOCOL])
{
case RAW_TEXT:
{
int len= data_length - 4;
// extract the channel number
if (data_length > 4)
{
if (len > sizeof(text_buf) - 2)
{
len= sizeof(text_buf) - 2;
}
memcpy(text_buf, &in_data[4], len);
text_buf[len] = '\0';
// do filtering and ignoring
len= filter_or_ignore_text((char*)text_buf, len, sizeof (text_buf), in_data[3]);
if (len > 0)
{
/* if from the server popup channel, and popup window usage enable */
if (use_server_pop_win && (in_data[3] == server_pop_chan))
display_server_popup_win((char*)text_buf);
/* else write to the chat window/console */
else
put_text_in_buffer (in_data[3], text_buf, len);
}
}
}
break;
case ADD_NEW_ACTOR:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
if (data_length <= 17)
{
log_error("CAUTION: Possibly forged ADD_NEW_ACTOR packet received.\n");
break;
}
add_actor_from_server((char*)&in_data[3], data_length-3);
}
break;
case ADD_NEW_ENHANCED_ACTOR:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
if (data_length <= 32)
{
log_error("CAUTION: Possibly forged ADD_ENHANCED_ACTOR packet received.\n");
break;
}
add_enhanced_actor_from_server((char*)&in_data[3], data_length-3);
}
break;
case ADD_ACTOR_COMMAND:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
// allow for multiple packets in a row
while(data_length >= 6){
add_command_to_actor(SDL_SwapLE16(*((short *)(in_data+3))), in_data[5]);
in_data+= 3;
data_length-= 3;
}
}
break;
case REMOVE_ACTOR:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
// allow for multiple packets in a row
while(data_length >= 5){
destroy_actor(SDL_SwapLE16(*((short *)(in_data+3))));
in_data+= 2;
data_length-= 2;
}
}
break;
case KILL_ALL_ACTORS:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
destroy_all_actors();
}
break;
case NEW_MINUTE:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
#ifdef DEBUG_TIME
return;
#endif
if (data_length <= 4)
{
log_error("CAUTION: Possibly forged NEW_MINUTE packet received.\n");
break;
}
#ifndef SKY_FPV
game_minute= SDL_SwapLE16(*((short *)(in_data+3)));
game_minute %= 360;
#else // SKY_FPV
real_game_minute= SDL_SwapLE16(*((short *)(in_data+3)));
real_game_minute %= 360;
real_game_second = 0;
next_second_time = cur_time+1000;
#endif // SKY_FPV
new_minute();
new_minute_console();
}
break;
case LOG_IN_OK:
{
char str[256];
// login and/or new character windows are no longer needed
if (login_root_win >= 0) destroy_window (login_root_win);
login_root_win = -1;
if (newchar_root_win >= 0) {
destroy_window (newchar_root_win);
hide_window( namepass_win );
hide_window( color_race_win );
}
newchar_root_win = -1;
show_window (game_root_win);
safe_snprintf(str,sizeof(str),"(%s on %s) %s",username_str,get_server_name(),win_principal);
SDL_WM_SetCaption(str, "eternallands" );
#if defined NEW_SOUND
// Try to turn on the music as it isn't needed up until now
if (music_on)
turn_music_on();
#endif // NEW_SOUND
load_quickspells();
load_counters();
send_video_info();
previously_logged_in=1;
}
// Print the game date cos its pretty (its also needed for SKY_FPV to set moons for signs, wonders, times and seasons)
command_date("", 0);
#ifdef SKY_FPV
// print the game time in order to get the seconds for the SKY_FPV feature
command_time("", 0);
#endif // SKY_FPV
break;
case HERE_YOUR_STATS:
{
if (data_length <= 167)
{
log_error("CAUTION: Possibly forged HERE_YOUR_STATS packet received.\n");
break;
}
get_the_stats((Sint16 *)(in_data+3));
}
break;
case SEND_PARTIAL_STAT:
{
// allow for multiple stats in a row
while (data_length >= 8)
{
get_partial_stat (in_data[3], SDL_SwapLE32(*((Sint32 *)(in_data+4))));
in_data+= 5;
data_length-= 5;
}
}
break;
case GET_KNOWLEDGE_LIST:
{
Uint16 size;
if (data_length <= 1)
{
log_error("CAUTION: Possibly forged GET_KNOWLEDGE_LIST packet received.\n");
break;
}
size = SDL_SwapLE16(*(Uint16 *)(in_data+1))-1;
if (data_length <= size + 2)
{
log_error("CAUTION(2): Possibly forged GET_KNOWLEDGE_LIST packet received.\n");
break;
}
get_knowledge_list(size, (char*)in_data+3);
}
break;
case GET_NEW_KNOWLEDGE:
{
if (data_length <= 4)
{
log_error("CAUTION: Possibly forged GET_NEW_KNOWLEDGE packet received.\n");
break;
}
get_new_knowledge(SDL_SwapLE16(*(Uint16 *)(in_data+3)));
}
break;
case HERE_YOUR_INVENTORY:
{
int items;
if (data_length <= 3)
{
log_error("CAUTION: Possibly forged HERE_YOUR_INVENTORY packet received.\n");
break;
}
items = in_data[3];
if (data_length <= items * 8)
{
log_error("CAUTION(2): Possibly forged HERE_YOUR_INVENTORY packet received.\n");
break;
}
inventory_item_string[0]=0;
inventory_item_string_id=0;
get_your_items(in_data+3);
}
break;
case GET_NEW_INVENTORY_ITEM:
{
// allow for multiple packets in a row
while(data_length >= 11){
get_new_inventory_item(in_data+3);
in_data+= 8;
data_length-= 8;
}
}
break;
case REMOVE_ITEM_FROM_INVENTORY:
{
// allow for multiple packets in a row
while(data_length >= 4)
{
remove_item_from_inventory (in_data[3]);
in_data+= 1;
data_length-= 1;
}
}
break;
case INVENTORY_ITEM_TEXT:
{
if (data_length <= 3)
{
log_error("CAUTION: Possibly forged INVENTORY_ITEM_TEXT packet received.\n");
break;
}
safe_strncpy2(inventory_item_string, (const char *)&in_data[3], sizeof(inventory_item_string)-1, data_length - 3);
inventory_item_string[sizeof(inventory_item_string)-1] = 0;
inventory_item_string_id++;
if(!(get_show_window(items_win)||get_show_window(manufacture_win)||get_show_window(trade_win)))
{
put_text_in_buffer(CHAT_SERVER, &in_data[3], data_length-3);
}
// Start a new block, since C doesn't like variables declared in the middle of a block.
{
char *teststring = "You successfully created ";
int testlen = strlen(teststring);
if ( (data_length > testlen+4) && (!strncmp((char*)in_data+4, teststring, testlen)) )
{
char *restofstring = malloc(data_length - 4 - testlen + 1);
safe_strncpy(restofstring, (char*)in_data + 4 + testlen, data_length - 4 - testlen + 1);
if (strlen(restofstring) > 0)
{
int product_count = atoi(restofstring);
char *product = restofstring;
while (*product!='\0' && *product!= ' ')
product++;
if (strlen(product)>1)
counters_set_product_info(product+1, product_count);
}
free(restofstring);
}
// if we don't get the product name, make sure we don't just count it as the last item.
else
counters_set_product_info("",0);
} // End counters block
}
break;
case SPELL_ITEM_TEXT:
{
if (data_length <= 3)
{
log_error("CAUTION: Possibly forged SPELL_ITEM_TEXT packet received.\n");
break;
}
put_small_text_in_box(in_data+3, data_length-3, 6*51+100, (char*)spell_text);
if(sigil_win==-1||!windows_list.window[sigil_win].displayed)
put_text_in_buffer (CHAT_SERVER, in_data+3, data_length-3);
have_error_message=1;
}
break;
case GET_KNOWLEDGE_TEXT:
{
if (data_length <= 3)
{
log_error("CAUTION: Possibly forged GET_KNOWLEDGE_TEXT packet received.\n");
break;
}
put_small_text_in_box(&in_data[3],data_length-3,6*51+150,knowledge_string);
}
break;
case CHANGE_MAP:
{
char mapname[1024];
if (data_length <= 4)
{
log_error("CAUTION: Possibly forged CHANGE_MAP packet received.\n");
break;
}
safe_strncpy2(mapname, (char*)in_data + 3, sizeof(mapname), data_length - 3);
change_map(mapname);
}
break;
case GET_TELEPORTERS_LIST:
{
Uint16 teleporters_no;
#ifdef EXTRA_DEBUG
ERR();
#endif
if (data_length <= 4)
{
log_error ("CAUTION: Possibly forged GET_TELEPORTERS_LIST packet received.\n");
break;
}
teleporters_no = SDL_SwapLE16 (*((Uint16 *)(in_data + 3)));
if (data_length <= teleporters_no * 5 + 4)
{
log_error ("CAUTION(2): Possibly forged GET_TELEPORTERS_LIST packet received.\n");
break;
}
add_teleporters_from_list (in_data+3);
}
break;
case PLAY_MUSIC:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
#ifdef NEW_SOUND
if (data_length <= 4)
{
log_error("CAUTION: Possibly forged PLAY_MUSIC packet received.\n");
break;
}
if(music_on)play_music(SDL_SwapLE16(*((short *)(in_data+3))));
#endif // NEW_SOUND
}
break;
case PLAY_SOUND:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
#ifdef NEW_SOUND
if (data_length <= 8)
{
log_error("CAUTION: Possibly forged PLAY_SOUND packet received.\n");
break;
}
if (sound_on) add_server_sound(SDL_SwapLE16(*((short *)(in_data+3))), SDL_SwapLE16(*((short *)(in_data+5))), SDL_SwapLE16(*((short *)(in_data+7))), 1.0f);
#endif // NEW_SOUND
}
break;
case TELEPORT_OUT:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
if (data_length <= 6)
{
log_error("CAUTION: Possibly forged TELEPORT_OUT packet received.\n");
break;
}
add_particle_sys_at_tile("./particles/teleport_out.part", SDL_SwapLE16(*((short *)(in_data+3))), SDL_SwapLE16 (*((short *)(in_data+5))), 1);
}
break;
case TELEPORT_IN:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
if (data_length <= 6)
{
log_error("CAUTION: Possibly forged TELEPORT_IN packet received.\n");
break;
}
add_particle_sys_at_tile("./particles/teleport_in.part", SDL_SwapLE16(*((short *)(in_data+3))), SDL_SwapLE16(*((short *)(in_data+5))), 1);
}
break;
case LOG_IN_NOT_OK:
{
if (data_length <= 4)
{
log_error("CAUTION: Possibly forged LOG_IN_NOT_OK packet received.\n");
break;
}
set_login_error ((char*)&in_data[3], data_length - 3, 1);
}
break;
case REDEFINE_YOUR_COLORS:
{
set_login_error (redefine_your_colours, strlen (redefine_your_colours), 0);
}
break;
case YOU_DONT_EXIST:
{
set_login_error (char_dont_exist, strlen (char_dont_exist), 1);
}
break;
case CREATE_CHAR_NOT_OK:
{
if (data_length <= 4)
{
log_error("CAUTION: Possibly forged CREATE_CHAR_NOT_OKAY packet received.\n");
break;
}
set_create_char_error ((char*)&in_data[3], data_length - 3);
return;
}
break;
case CREATE_CHAR_OK:
{
login_from_new_char();
}
break;
case YOU_ARE:
{
#ifdef EXTRA_DEBUG
ERR();
#endif
if (data_length <= 4)
{
log_error("CAUTION: Possibly forged YOU_ARE packet received.\n");
break;
}
LOCK_ACTORS_LISTS();
yourself= SDL_SwapLE16(*((short *)(in_data+3)));
set_our_actor (get_actor_ptr_from_id (yourself));
UNLOCK_ACTORS_LISTS();
}
break;
case START_RAIN:
{
float severity;
#ifdef EXTRA_DEBUG
ERR();
#endif
if (data_length <= 3)
{
log_error("CAUTION: Possibly forged START_RAIN packet received.\n");
break;
}
if (data_length > 4) {
severity= 0.1f + 0.9f * (in_data[4] / 255.0f);
} else {
severity= 1.0f;
}
#ifndef NEW_WEATHER
start_weather (in_data[3], severity);
#else // NEW_WEATHER
weather_set_area(0, tile_map_size_x*1.5, tile_map_size_y*1.5, 100000.0, 1, severity, in_data[3]);
#endif // NEW_WEATHER
}
break;
case STOP_RAIN:
{
float severity;
#ifdef EXTRA_DEBUG
ERR();
#endif
if (data_length <= 3)
{
log_error("CAUTION: Possibly forged STOP_RAIN packet received.\n");
break;
}