-
Notifications
You must be signed in to change notification settings - Fork 57
/
console.c
executable file
·2314 lines (2016 loc) · 57.6 KB
/
console.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 <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "actors_list.h"
#include "asc.h"
#include "buddy.h"
#include "cache.h"
#include "cal.h"
#include "chat.h"
#include "consolewin.h"
#include "elconfig.h"
#ifdef ANDROID
#include "events.h"
#endif
#include "filter.h"
#include "gamewin.h"
#include "gl_init.h"
#include "hud.h"
#include "hud_quickspells_window.h"
#include "ignore.h"
#include "icon_window.h"
#include "init.h"
#include "item_lists.h"
#include "interface.h"
#include "invasion_window.h"
#include "knowledge.h"
#include "list.h"
#include "mapwin.h"
#include "manufacture.h"
#include "misc.h"
#include "multiplayer.h"
#include "new_actors.h"
#include "notepad.h"
#include "password_manager.h"
#include "pm_log.h"
#include "platform.h"
#include "questlog.h"
#include "sound.h"
#include "spells.h"
#include "stats.h"
#include "tabs.h"
#include "translate.h"
#include "url.h"
#include "command_queue.h"
#include "counters.h"
#include "map.h"
#include "minimap.h"
#include "errors.h"
#include "io/elpathwrapper.h"
#include "io/elfilewrapper.h"
#include "calc.h"
#include "text_aliases.h"
//only for debugging command #add_emote <actor name> <emote id>, can be removed later
#include "actor_scripts.h"
#include "emotes.h"
#ifdef CUSTOM_UPDATE
#include "custom_update.h"
#endif /* CUSTOM_UPDATE */
typedef char name_t[32];
#define MAX_COMMAND_NAME_LEN 64
typedef struct {
char command[MAX_COMMAND_NAME_LEN];
int (*callback)();
} command_t;
char auto_open_encyclopedia = 1;
int time_warn_h = -1, time_warn_s = -1, time_warn_d = -1;
/* Pointer to the array holding the commands */
static command_t *commands;
/* Array holding names we have seen (for completion) */
static name_t *name_list = NULL;
/* Counts how many commands we have */
static Uint16 command_count = 0;
static Uint16 name_count = 0;
/* The command buffer head pointer */
static list_node_t *command_buffer = NULL;
/* Pointer to our position in the buffer */
static list_node_t *command_buffer_offset = NULL;
/* The input line before we started moving around in the buffer. */
static char first_input[256] = {0};
// invasion window command strings
static const char * invasion_win_long_cmd_str = "invasion_win";
static const char * invasion_win_short_cmd_str = "iwin";
static const char * invasion_seq_stop_long_cmd_str = "stop_invasion_seq";
static const char * invasion_seq_stop_short_cmd_str = "istop";
void add_line_to_history(const char *line, int len)
{
char *copy;
copy = malloc(len+1);
safe_snprintf(copy, len+1, "%.*s", len, line);
list_push(&command_buffer, copy);
command_buffer_offset = NULL;
}
char *history_get_line_up(void)
{
if(command_buffer_offset == NULL) {
/* This is the first up keypress.
* Return the first line we have, if there's one and remember what we had. */
command_buffer_offset = command_buffer;
safe_snprintf(first_input, sizeof(first_input), "%.*s", input_text_line.len, input_text_line.data);
} else if(command_buffer_offset->next != NULL) {
command_buffer_offset = command_buffer_offset->next;
}
if(command_buffer_offset != NULL) {
return command_buffer_offset->data;
} else {
return NULL;
}
}
char *history_get_line_down(void)
{
if(command_buffer_offset != NULL) {
command_buffer_offset = command_buffer_offset->prev;
if(command_buffer_offset != NULL) {
return command_buffer_offset->data;
} else {
/* We're at the bottom of the list, return what we initially had. */
return first_input;
}
}
return NULL;
}
void history_reset(void)
{
command_buffer_offset = NULL;
}
void history_destroy(void)
{
list_destroy(command_buffer);
}
static void cleanup_commands_help(void);
void command_cleanup(void)
{
if(command_count > 0) {
free(commands);
}
if(name_count > 0) {
free(name_list);
}
cleanup_commands_help();
}
static void add_command(const char *command, int (*callback)())
{
static int commands_size = 0;
int i;
/* Check if the command already is in the list. */
for(i = 0; i < command_count; i++) {
if(strcasecmp(commands[i].command, command) == 0) {
/* It exists, just update the callback and return */
commands[i].callback = callback;
return;
}
}
if(command_count >= commands_size) {
if(commands_size == 0) {
commands_size += 10;
commands = malloc(commands_size*sizeof(*commands));
} else {
commands_size *= 2;
commands = realloc(commands, commands_size*sizeof(*commands));
}
}
safe_snprintf(commands[command_count].command, sizeof(commands[command_count].command), "%s", command);
commands[command_count].callback = callback;
command_count++;
}
void add_name_to_tablist(const char *name)
{
static int list_size = 0;
int i;
for(i = 0; i < name_count; i++) {
if(strcasecmp(name_list[i], name) == 0) {
/* Name is already in the list, do nothing */
return;
}
}
if(name_count >= list_size) {
if(list_size == 0) {
list_size += 10;
}
list_size *= 2;
name_list = realloc(name_list, list_size * sizeof(*name_list));
}
safe_snprintf(name_list[name_count], sizeof(name_list[name_count]), "%s", name);
name_count++;
}
/* strmrchr: returns a pointer to the last occurence of c in s,
* beginning the (reversed) search at begin */
static const char *strmrchr(const char *s, const char *begin, int c)
{
char *copy = strdup(s);
char *cbegin = copy+(begin-s);
char *result;
*cbegin = '\0';
result = strrchr(copy, c);
if(result == NULL) {
free(copy);
return NULL;
} else {
const char *ret = s+(result-copy);
free(copy);
return ret;
}
}
enum compl_type {
COMMAND = 1,
NAME,
NAME_PM,
CHANNEL
};
struct compl_str {
const char *str;
enum compl_type type;
};
// return true if the command is in the exclude list
static int exclude_command(const char * command)
{
const char * const exclude_commands[] = {invasion_win_long_cmd_str, invasion_win_short_cmd_str,
invasion_seq_stop_long_cmd_str, invasion_seq_stop_short_cmd_str};
const size_t num_exclude = sizeof(exclude_commands) / sizeof(char *);
int j;
// if we want to exclude non invasion window commands, we will need to change this ...
if (invasion_window_enabled())
return 0;
for (j = 0; j < num_exclude; j++)
if (strcasecmp(command, exclude_commands[j]) == 0)
return 1;
return 0;
}
static struct compl_str tab_complete(const text_message *input, unsigned int cursor_pos)
{
static char last_complete[48] = {0};
static int have_last_complete = 0;
static int last_str_count = -1;
static enum compl_type last_type = NAME;
struct compl_str return_value = {NULL, 0};
if(input != NULL && input->len > 0 )
{
const char *input_string = (char*)input->data;
int count;
short retries;
if(!have_last_complete) {
if(cursor_pos > 0 &&
strmrchr(input_string, input_string+cursor_pos-1, ' ') != NULL) {
/* If we have a space in the input string, we're pretty certain
* it's not a PM-name, command or channel name. */
return_value.type = NAME;
} else if(*input_string == '/' || *input_string == *char_slash_str) {
return_value.type = NAME_PM;
} else if (*input_string == '@' || *input_string == *char_at_str) {
return_value.type = CHANNEL;
} else if(*input_string == '#' || *input_string == *char_cmd_str) {
return_value.type = COMMAND;
} else {
return_value.type = NAME;
}
} else {
return_value.type = last_type;
}
switch(return_value.type) {
case CHANNEL:
input_string++;
/* No break, increment twice for channel */
// Fallthrough
case NAME_PM:
case COMMAND:
input_string++;
break;
case NAME:
{
const char *last_space = strmrchr(input_string, input_string+cursor_pos, ' ');
if(last_space != NULL) {
/* Update the cursor position to be relative to last_complete */
cursor_pos -= last_space+1-input_string;
input_string = last_space+1;
}
}
break;
}
if(!have_last_complete || (*input_string && strncasecmp(input_string, last_complete, strlen(last_complete)) != 0)) {
/* New input string, start over */
size_t i;
last_str_count = -1;
/* Isolate the word we're currently typing (and completing) */
for(i = 0;
i+1 < sizeof(last_complete) &&
input_string[i] && i < cursor_pos &&
!isspace((unsigned char)input_string[i]);
i++) {
last_complete[i] = input_string[i];
}
last_complete[i] = '\0';
have_last_complete = 1;
}
/* Look through the list */
for(retries = 0; retries < 2 && !return_value.str; retries++) {
size_t i;
switch(return_value.type) {
case NAME:
case NAME_PM:
for(i = 0, count = 0; i < name_count; i++) {
if(strncasecmp(name_list[i], last_complete, strlen(last_complete)) == 0) {
/* We have a match! */
if(count > last_str_count) {
/* This hasn't been returned yet, let's return it */
last_str_count = count++;
return_value.str = name_list[i];
break;
}
count++;
}
}
break;
case CHANNEL:
for(set_first_tab_channel(), count = 0; get_tab_channel_name() != NULL; set_next_tab_channel()) {
if(strncasecmp(get_tab_channel_name(), last_complete, strlen(last_complete)) == 0) {
/* Yay! The chan-name begins with the string we're searching for. */
if(count > last_str_count) {
/* We found something we haven't returned earlier, let's return it. */
last_str_count = count++;
return_value.str = get_tab_channel_name();
break;
}
count++;
}
}
break;
case COMMAND:
default:
for(i = 0, count = 0; i < command_count; i++) {
if (exclude_command(commands[i].command))
continue;
if(strncasecmp(commands[i].command, last_complete, strlen(last_complete)) == 0) {
/* Yay! The command begins with the string we're searching for. */
if(count > last_str_count) {
/* We found something we haven't returned earlier, let's return it. */
last_str_count = count++;
return_value.str = commands[i].command;
break;
}
count++;
}
}
break;
}
if(!return_value.str && count) {
/* We checked the whole list and found something, but not
* anything we haven't returned earlier. Let's start from the beginning again. */
last_str_count = -1;
}
}
last_type = return_value.type;
} else {
have_last_complete = 0;
*last_complete = '\0';
last_str_count = -1;
}
return return_value;
}
void do_tab_complete(text_message *input)
{
int input_cursor = get_console_input_cursor();
struct compl_str completed = tab_complete(input, input_cursor);
if(completed.str != NULL)
{
size_t len;
size_t i;
/* Find the length of the data we're removing */
if(completed.type == NAME) {
const char *last_space = strmrchr(input->data, input->data+input_cursor, ' ');
/* Name is a bit special because it can be anywhere in a string,
* not just at the beginning like the other types. */
len = input->data+input_cursor-1-(last_space ? last_space : (input->data-1));
} else if (completed.type == CHANNEL) {
len = input_cursor-2;
} else {
len = input_cursor-1;
}
/* Erase the current input word */
for (i = input_cursor; i <= input->len; i++) {
input->data[i-len] = input->data[i];
}
input->len -= len;
set_console_input_cursor(input_cursor - len);
paste_in_input_field((unsigned char*)completed.str);
input->len = strlen(input->data);
}
}
void reset_tab_completer(void)
{
tab_complete(NULL, 0);
}
int test_for_console_command(char *text, int length)
{
int i;
int ptr_length = length;
char *text_ptr = text;
// Skip leading #s
if(*text == '#' || *text == char_cmd_str[0]) {
*text = '#';
text++;
length--;
}
//Skip leading spaces
for(;isspace(*text); text++,length--);
//Check if there's anything left of the command
if (length <= 0 || (*text == '@' && length <= 1)) {
return 0;
} else {
int cmd_len;
/* Handle numeric shortcuts */
if ( isdigit(text[0]) ) {
if ( process_text_alias(text,length) >= 0 ) {
return 1;
}
}
/* Look for a matching command */
for(i = 0; i < command_count; i++) {
cmd_len = strlen(commands[i].command);
if(strlen(text) >= cmd_len && !strncasecmp(text, commands[i].command, cmd_len) && (isspace(text[cmd_len]) || text[cmd_len] == '\0')) {
/* Command matched */
if(commands[i].callback && commands[i].callback(text+cmd_len, length-cmd_len)) {
/* The command was handled and we don't want to send it to the server */
return 1;
} else {
/* the command wants to be sent to the server */
break;
}
}
}
}
send_input_text_line (text_ptr, ptr_length);
return 0;
}
// -------- COMMAND CALLBACKS -------- //
// Return 0 if you want the string to be sent to the server.
// the first argument passed is the input string without the command itself
// if ie. '#filter foo' is passed to test_for_console_command(), only ' foo' is passed to the callback.
/* given the command text, return the start of any parameter text */
/* e.g. find first space, then skip any spaces */
static char *getparams(char *text)
{
while(*text && !isspace(*text))
text++;
while(*text && isspace(*text))
text++;
return text;
}
static int print_emotes(char *text, int len){
hash_entry *he;;
LOG_TO_CONSOLE(c_orange1,"EMOTES");
LOG_TO_CONSOLE(c_orange1,"--------------------");
hash_start_iterator(emote_cmds);
while((he=hash_get_next(emote_cmds)))
LOG_TO_CONSOLE(c_orange1,((emote_dict *)he->item)->command);
return 1;
}
#ifdef EMOTES_DEBUG
int add_emote(char *text, int len){
int j;
char *id;
locked_list_ptr actors_list;
actor *act;
for(j=1;j<len;j++) if(text[j]==' ') {text[j]=0; break;}
id=&text[j+1];
text++;
printf("Actor [%s] [%s]\n",text,id);
actors_list = lock_and_get_actor_from_name(text, &act);
if (!actors_list)
{
LOG_TO_CONSOLE(c_orange1, "actor not found");
return 1;
}
LOG_TO_CONSOLE(c_orange1, "actor found, adding emote");
printf("actor found\n");
add_emote_to_actor(act->actor_id,atoi(id));
printf("message added %s\n",id);
release_locked_actors_list_and_invalidate(actors_list, &me);
*(id-1)=' ';
return 1;
}
static int send_cmd(char *text, int len){
int j,x;
char *id;
locked_list_ptr actors_list;
actor *act, *attached;
for(j=1;j<len;j++) if(text[j]==' ') {text[j]=0; break;}
id=&text[j+1];
x=j;
text++;
printf("Actor [%s] [%s]\n",text,id);
actors_list = lock_and_get_actor_from_name(text, &act);
if (!actors_list)
{
LOG_TO_CONSOLE(c_orange1, "actor not found");
return 1;
}
LOG_TO_CONSOLE(c_orange1, "actor found, adding command");
printf("actor found\n");
attached = has_attachment(act) ? get_actor_from_id(actors_list, act->attached_actor_id) : NULL;
while(*id)
{
add_command_to_actor_locked(act, attached, atoi(id));
id++;
while(*id!=' '&&*id!=0) id++;
}
printf("command added %s\n",id);
release_locked_actors_list_and_invalidate2(actors_list, &act, &attached);
text[x-1]=' ';
return 1;
}
static int set_idle(char *text, int len){
int j,x;
char *id;
locked_list_ptr actors_list;
actor *act;
struct CalMixer *mixer;
for(j=1;j<len;j++) if(text[j]==' ') {text[j]=0; break;}
id=&text[j+1];
x=j;
text++;
printf("Actor [%s] [%s]\n",text,id);
actors_list = lock_and_get_actor_from_name(text, &act);
if (!actors_list)
{
LOG_TO_CONSOLE(c_orange1, "actor not found");
return 1;
}
mixer=CalModel_GetMixer(act->calmodel);
LOG_TO_CONSOLE(c_orange1, "actor found, adding anims");
printf("actor found\n");
CalMixer_ClearCycle(mixer,act->cur_anim.anim_index, 0.0f);
while(*id)
{
int anim_id;
double anim_wg;
anim_id=atoi(id);
id++;
while(*id!=' '&&*id!=0) id++;
anim_wg=atof(id);
id++;
while(*id!=' '&&*id!=0) id++;
printf("setting anim %i with weight %f\n",anim_id,anim_wg);
if(anim_wg<0) CalMixer_ClearCycle(mixer,actors_defs[act->actor_type].cal_frames[anim_id].anim_index, 0.0f);
else CalMixer_BlendCycle(mixer,actors_defs[act->actor_type].cal_frames[anim_id].anim_index,anim_wg, 0.1f);
}
printf("command added %s\n",id);
release_locked_actors_list_and_invalidate(actors_list, &act);
text[x-1]=' ';
return 1;
}
static int set_action(char *text, int len){
int j,x;
char *id;
locked_list_ptr actors_list;
actor *act;
struct CalMixer *mixer;
for(j=1;j<len;j++) if(text[j]==' ') {text[j]=0; break;}
id=&text[j+1];
x=j;
text++;
printf("Actor [%s] [%s]\n",text,id);
actors_list = lock_and_get_actor_from_name(text, &act);
if (!actors_list)
{
LOG_TO_CONSOLE(c_orange1, "actor not found");
return 1;
}
mixer=CalModel_GetMixer(act->calmodel);
LOG_TO_CONSOLE(c_orange1, "actor found, adding anims");
printf("actor found\n");
while(*id)
{
int anim_id;
double anim_wg;
anim_id=atoi(id);
id++;
while(*id!=' '&&*id!=0) id++;
anim_wg=atof(id);
id++;
while(*id!=' '&&*id!=0) id++;
printf("setting action %i with weight %f\n",anim_id,anim_wg);
if(anim_wg<0) CalMixer_RemoveAction(mixer,actors_defs[act->actor_type].cal_frames[anim_id].anim_index);
else CalMixer_ExecuteActionExt(mixer,actors_defs[act->actor_type].cal_frames[anim_id].anim_index,0.0f,0.0f,anim_wg, 1);
}
printf("command added %s\n",id);
release_locked_actors_list_and_invalidate(actors_list, &act);
text[x-1]=' ';
return 1;
}
#endif
#ifdef MORE_ATTACHED_ACTORS_DEBUG
static int horse_cmd(char* text, int len){
int j,x;
char *id;
locked_list_ptr actors_list;
actor *act;
for(j=1;j<len;j++) if(text[j]==' ') {text[j]=0; break;}
id=&text[j+1];
x=j;
text++;
printf("Actor [%s] [%s] [%i]\n",text,id,atoi(id));
actors_list = lock_and_get_actor_from_name(text, &act);
text[x-1]=' ';
if (!actors_list)
{
LOG_TO_CONSOLE(c_orange1,"Actor doesn't exist");
return 1; // Eek! We don't have an actor match... o.O
}
LOG_TO_CONSOLE(c_orange1, "actor found, adding horse");
act->sit_idle=act->stand_idle=0;
if (has_attachment(act)){
//remove horse
remove_and_destroy_attachment(actors_list, act->actor_id);
LOG_TO_CONSOLE(c_orange1,"De-horsified");
} else {
//add horse
int hh=atoi(id);
if (hh<=0) hh=200;
add_actor_attachment(actors_list, act, hh);
LOG_TO_CONSOLE(c_orange1,"Horsified");
}
release_locked_actors_list_and_invalidate(actors_list, &act);
return 1;
}
#endif
#ifdef NECK_ITEMS_DEBUG
static int set_neck(char *text, int len){
int j;
char *id;
locked_list_ptr actors_list;
actor *act;
for(j=1;j<len;j++) if(text[j]==' ') {text[j]=0; break;}
id=&text[j+1];
text++;
printf("Actor [%s] [%s]\n",text,id);
actors_list = lock_and_get_actor_from_name(text, &act);
if (!actors_list)
{
LOG_TO_CONSOLE(c_orange1, "actor not found");
return 1;
}
LOG_TO_CONSOLE(c_orange1, "actor found, adding neck item");
printf("actor found\n");
if(atoi(id)) {
//wear
unwear_item_from_actor(act->actor_id,KIND_OF_NECK);
actor_wear_item(act->actor_id,KIND_OF_NECK, atoi(id));
} else {
//unwear
unwear_item_from_actor(act->actor_id,KIND_OF_NECK);
}
release_locked_actors_list_and_invalidate(actors_list, &act);
*(id-1)=' ';
return 1;
}
#endif
static int command_cls(char *text, int len)
{
clear_display_text_buffer ();
return 1;
}
static int command_calc(char *text, int len)
{
double res;
char str[100];
int calcerr;
res = calc_exp(text, &calcerr);
switch (calcerr){
case CALCERR_OK:
if (trunc(res)==res) safe_snprintf (str,sizeof(str), "%s = %.0lf",text,res);
else safe_snprintf (str,sizeof(str), "%s = %.2lf",text,res);
LOG_TO_CONSOLE (c_orange1, str);
break;
case CALCERR_SYNTAX:
safe_snprintf (str,sizeof(str), "%s = Syntax error",text);
LOG_TO_CONSOLE (c_orange1, str);
break;
case CALCERR_DIVIDE:
safe_snprintf (str, sizeof(str),"%s = Divide by zero",text);
LOG_TO_CONSOLE (c_orange1, str);
break;
case CALCERR_MEM:
safe_snprintf (str,sizeof(str), "%s = Memory error",text);
LOG_TO_CONSOLE (c_orange1, str);
break;
case CALCERR_XOPSYNTAX:
safe_snprintf (str,sizeof(str), "%s = Bad argument for X", text);
LOG_TO_CONSOLE (c_orange1, str);
break;
case CALCERR_LOPSYNTAX:
safe_snprintf (str,sizeof(str), "%s = Bad argument for L", text);
LOG_TO_CONSOLE (c_orange1, str);
break;
case CALCERR_EOPSYNTAX:
safe_snprintf (str,sizeof(str), "%s = Bad argument for E", text);
LOG_TO_CONSOLE (c_orange1, str);
break;
case CALCERR_NOPSYNTAX:
safe_snprintf (str,sizeof(str), "%s = Bad argument for N", text);
LOG_TO_CONSOLE (c_orange1, str);
break;
case CALCERR_ZOPSYNTAX:
safe_snprintf (str,sizeof(str), "%s = Bad argument for Z", text);
LOG_TO_CONSOLE (c_orange1, str);
break;
case CALCERR_QOPSYNTAX:
safe_snprintf (str,sizeof(str), "%s = Bad argument for Q", text);
LOG_TO_CONSOLE (c_orange1, str);
break;
}
return 1;
}
static int command_markpos(char *text, int len)
{
int map_x, map_y;
char *ptr = text;
char msg[512];
const char *usage = help_cmd_markpos_str;
while (isspace(*ptr))
ptr++;
if (sscanf(ptr, "%d,%d ", &map_x, &map_y) != 2) {
LOG_TO_CONSOLE(c_red2, usage);
return 1;
}
while (*ptr != ' ' && *ptr)
ptr++;
while (*ptr == ' ')
ptr++;
if (!*ptr) {
LOG_TO_CONSOLE(c_red2, usage);
return 1;
}
if (put_mark_on_position(map_x, map_y, ptr)) {
safe_snprintf (msg, sizeof(msg), location_info_str, map_x, map_y, ptr);
LOG_TO_CONSOLE(c_orange1,msg);
} else {
safe_snprintf (msg,sizeof(msg), invalid_location_str, map_x, map_y);
LOG_TO_CONSOLE(c_red2,msg);
}
return 1;
}
int command_mark(char *text, int len)
{
if (strlen(text) > 1) //check for empty marks
{
char str[512];
for(;isspace(*text); text++);
if(strlen(text) > 0) {
if (put_mark_on_current_position(text))
{
safe_snprintf (str, sizeof(str), marked_str, text);
LOG_TO_CONSOLE(c_orange1,str);
}
}
}
return 1;
}
int command_unmark_special(char *text, int len, int do_log)
{
int i;
while (isspace(*text))
text++;
if(*text) {
for (i = 0; i < max_mark; i ++)
{
if (!strcasecmp(marks[i].text, text) && (marks[i].x != -1))
{
char str[512];
marks[i].x = marks[i].y = -1;
if (marks[i].server_side)
{
hash_delete(server_marks,(void *)(uintptr_t)(marks[i].server_side_id));
save_server_markings();
}
if (do_log)
{
safe_snprintf(str, sizeof(str), unmarked_str, marks[i].text);
LOG_TO_CONSOLE(c_orange1, str);
}
save_markings();
load_map_marks(); // simply to compact the array and make room for new marks
break;
}
}
}
return 1;
}
int command_unmark(char *text, int len)
{
return command_unmark_special(text, len, 1);
}
static int command_mark_color(char *text, int len)
{
char str[512];
while (isspace(*text))
text++;
if(*text) {
int r=-1,g,b;
if(sscanf(text,"%d %d %d",&r,&g,&b)==3) {
if(!(r>=0&&r<=255&&g>=0&&g<=255&&b>=0&&b<=255)) r=-1; //don't set color
} else {
if(strcasecmp(text,"red")==0) {r=255;g=0;b=0;}
else if(strcasecmp(text,"blue")==0) {r=0;g=0;b=255;}
else if(strcasecmp(text,"green")==0) {r=0;g=255;b=0;}
else if(strcasecmp(text,"yellow")==0) {r=255;g=255;b=0;}
else if(strcasecmp(text,"cyan")==0) {r=0;g=255;b=255;}
else if(strcasecmp(text,"magenta")==0) {r=255;g=0;b=255;}
else if(strcasecmp(text,"white")==0) {r=255;g=255;b=255;}
}
if(r>-1) {
//set color
curmark_r=r;
curmark_g=g;
curmark_b=b;
}
}
safe_snprintf (str, sizeof(str), "Current marker color is (RGB): %d %d %d", curmark_r,curmark_g,curmark_b);
LOG_TO_CONSOLE(c_orange1,str);
return 1;
}
static int command_stats(char *text, int len)
{
unsigned char protocol_name = SERVER_STATS;
my_tcp_send(&protocol_name, 1);
return 1;
}
int command_time(char *text, int len)
{
unsigned char protocol_name = GET_TIME;
my_tcp_send(&protocol_name, 1);
return 1;
}
int command_ping(char *text, int len)
{
Uint8 str[5] = { PING };
*((Uint32 *)(str+1)) = SDL_SwapLE32(SDL_GetTicks());
my_tcp_send(str, 5);
return 1;
}
int command_date(char *text, int len)
{
unsigned char protocol_name = GET_DATE;
my_tcp_send(&protocol_name, 1);
return 1;
}
static int command_quit(char *text, int len)
{
exit_now = 1;
return 1;
}