-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomm.cpp
executable file
·2309 lines (2024 loc) · 59.4 KB
/
comm.cpp
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
/****************************************************************************
* [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame | \\._.// *
* -----------------------------------------------------------| (0...0) *
* SMAUG 1.0 (C) 1994, 1995, 1996 by Derek Snider | ).:.( *
* -----------------------------------------------------------| {o o} *
* SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus, | / ' ' \ *
* Scryn, Rennard, Swordbearer, Gorog, Grishnakh and Tricops |~'~.VxvxV.~'~*
* ------------------------------------------------------------------------ *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* ------------------------------------------------------------------------ *
* Low-level communication module *
****************************************************************************/
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <crypt.h>
#include "mud.h"
#include "mxp.h"
#include "quests.h"
#include "paths.const.h"
/*
* Socket and TCP/IP stuff.
*/
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <arpa/telnet.h>
#include <netdb.h>
#include <assert.h>
#include "connection_manager.h"
#include "connection.h"
#include "World.h"
#include "db_public.h"
// STL includes
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
const unsigned char echo_off_str [] = { IAC, WILL, TELOPT_ECHO, '\0' };
const unsigned char echo_on_str [] = { IAC, WONT, TELOPT_ECHO, '\0' };
const unsigned char go_ahead_str [] = { IAC, GA, '\0' };
const unsigned char will_mxp_str [] = { IAC, WILL, TELOPT_MXP, '\0' };
const unsigned char start_mxp_str [] = { IAC, SB, TELOPT_MXP, IAC, SE, '\0' };
const unsigned char do_mxp_str [] = { IAC, DO, TELOPT_MXP, '\0' };
const unsigned char dont_mxp_str [] = { IAC, DONT, TELOPT_MXP, '\0' };
void send_auth ( struct descriptor_data *d ) ;
void read_auth ( struct descriptor_data *d ) ;
void start_auth ( struct descriptor_data *d );
void save_sysdata ( SYSTEM_DATA sys ) ;
/*
* Global variables.
*/
ACCOUNT_DATA * first_account;
ACCOUNT_DATA * last_account;
//DESCRIPTOR_DATA * first_descriptor; /* First descriptor */
//DESCRIPTOR_DATA * last_descriptor; /* Last descriptor */
//DESCRIPTOR_DATA * d_next; /* Next descriptor in loop */
int ListenerDescriptor; // the main listener socket
int ListenerPort; // the main listener port
FILE * fpReserve; /* Reserved file handle */
bool gGameRunning; // Is the game running?
bool gBooting; // Are we currently booting?
bool shell_shutdown = FALSE; /* was it killed via a HUP? */
bool wizlock; /* Game is wizlocked */
bool newbielock; /* Game does not accept newbies */
time_t secBootTime;
HOUR_MIN_SEC set_boot_time_struct;
HOUR_MIN_SEC * set_boot_time;
struct tm * new_boot_time;
struct tm new_boot_struct;
char str_boot_time[MAX_INPUT_LENGTH];
char lastplayercmd[MAX_INPUT_LENGTH*2];
time_t secCurrentTime; // Time of this pulse
long nextActionTime; // time for the next action to happen, in milliseconds
//int port; /* Port number to be used */
//int control; /* Controlling descriptor */
//int control2; /* Controlling descriptor #2 */
//int conclient; /* MUDClient controlling desc */
//int conjava; /* JavaMUD controlling desc */
//int newdesc; /* New descriptor */
//fd_set in_set; /* Set of desc's for reading */
//fd_set out_set; /* Set of desc's for writing */
//fd_set exc_set; /* Set of desc's with errors */
//int maxdesc;
ConnectionManager * gConnectionManager;
World * gTheWorld;
QuestManager * gQuestManager;
DatabaseController * MasterDatabase;
bool fCopyOver = !FALSE; /* Are we doing a copyover type operation? */
/*
* OS-dependent local functions.
*/
void game_loop ( );
/*
* Other local functions (OS-independent).
*/
char* vnum_to_dotted (int vnum);
//bool mail_account_password (DESCRIPTOR_DATA* d, char* pword, char* file) ;
//bool check_parse_name ( char *name, DESCRIPTOR_DATA *d ) ;
//bool check_parse_email ( char *email, DESCRIPTOR_DATA *d ) ;
//bool check_reconnect args( ( DESCRIPTOR_DATA *d, char *name,
// bool fConn ) );
//bool check_playing ( DESCRIPTOR_DATA *d, char *name, bool kick ) ;
int main ( int argc, char **argv ) ;
//void nanny ( DESCRIPTOR_DATA *d, char *argument ) ;
//bool flush_buffer ( DESCRIPTOR_DATA *d, bool fPrompt ) ;
//void read_from_buffer ( DESCRIPTOR_DATA *d ) ;
void stop_idling ( CHAR_DATA *ch ) ;
//void free_desc ( DESCRIPTOR_DATA *d ) ;
//void display_prompt ( DESCRIPTOR_DATA *d ) ;
//int make_color_sequence args( ( const char *col, char *buf,
// DESCRIPTOR_DATA *d ) );
//void set_pager_input args( ( DESCRIPTOR_DATA *d,
// char *argument ) );
//bool pager_output ( DESCRIPTOR_DATA *d ) ;
void mail_count ( CHAR_DATA *ch ) ;
// forward declarations
void do_save(Character * ch, const char* argument);
void do_help(Character * ch, const char* argument);
CHAR_DATA * lastplayer; /* who typed lastplayercmd? */
/* *********** */
/* debug trace by Testaur - respects privacy of communication */
/* also avoids spammy direction commands */
int tracelines=0;
int tracenum=0;
FILE *tracefile=NULL;
void traceclose(void)
{
fclose(tracefile); /* close old tracefile */
}
void traceopen(void)
{
char cmd[20];
strcpy(cmd,"../tracef0.txt");
cmd[9] |= (tracenum & 1); /* build name of new file */
tracefile=fopen(cmd,"w");
tracelines=0; /* no lines so far */
fprintf(tracefile,"file %d\n",tracenum);
fflush(tracefile);
if(++tracenum==10)
tracenum=0;
}
#define notrace(str) { if( strcmp(cmd,str)==0 ){traceit=0;} }
void trace(CHAR_DATA *ch, const char *cmdline)
{
int traceit,c,i,j;
char cmd[40]; /* no command of interest is this long */
for (i=0; (c=cmdline[i]) > 0 && c < '!'; i++ )
; /* find start of command */
j=0;
while( (c=cmdline[i++]) > ' ' )
{
if(j<19)
{
if(c>='A' && c<='Z')
c|=0x20; /* to lower case */
cmd[j++]=c;
}
}
cmd[j]=0;
c=cmd[0];
traceit=1;
if((c>='a' && c<='z') || (c>='A' && c<='Z'))
{/* alpha command */
switch(c | 0x20) /* test lower case */
{
case 'c':
notrace("clan");
break;
case 'd':
notrace("d");
break;
case 'e':
notrace("e");
notrace("emote");
break;
case 'g':
notrace("gtalk");
break;
case 'i':
notrace("immtalk");
break;
case 'n':
notrace("n");
notrace("ne");
notrace("nw");
break;
case 'p':
break;
case 'r':
notrace("reply");
notrace("retell");
break;
case 's':
notrace("s");
notrace("se");
notrace("sw");
notrace("say");
break;
case 't':
notrace("tell");
notrace("think");
break;
case 'u':
notrace("u");
break;
case 'w':
notrace("w");
break;
}
}
else
{/* other command */
if(
c==0x27 /* single quote is 'say' */
|| c==','
|| c==';'
|| c=='/'
|| c==':'
|| c=='>'
)
traceit=0;
}
if(traceit)
{/* since this is none of the above commands, it is safe to trace */
strcpy(cmd, ((ch && ch->getName().length() > 0) ?
ch->getName().c_str(): "<null>" ));
if(tracefile)
{
fprintf(tracefile,"%s: %s\n",cmd,cmdline);
fflush(tracefile);
}
if(++tracelines>=100)
{/* full enough */
traceclose();
traceopen();
}
}
}
/* end of debug trace */
/* *********** */
void SanityFail( Character * ch, const string & msg )
{
assert(0);
}
void SanityObject( Character * ch, Object * obj )
{
// Check the object contents
Object * content = obj->first_content;
while ( content )
{
Object * next = content->next_content;
if ( next )
{
// make sure next's prev is us
if ( next->prev_content != content )
{
SanityFail(ch, "next->prev != me (content)");
return;
}
}
else
{
// no next, make sure I'm the last
if ( obj->last_content != content )
{
SanityFail(ch, "obj with null next is NOT last_content (content)");
return;
}
}
SanityObject(ch, content);
content = content->next_content;
}
}
// Sanity check function, implemented by Ksilyan
void SanityCheck( Character * ch )
{
// if we're not debugging... don't do this stuff.
#ifndef DEBUG
return;
#endif
// OK... check this player's objects
Object * obj = ch->first_carrying;
while ( obj )
{
Object * next = obj->next_content;
if ( next )
{
// make sure next's prev is us
if ( next->prev_content != obj )
{
SanityFail(ch, "next->prev != me");
return;
}
}
else
{
// no next, so make sure I'm the last
if ( ch->last_carrying != obj )
{
SanityFail(ch, "obj with null next is NOT last_carry");
return;
}
}
SanityObject(ch, obj);
obj = obj->next_content;
}
}
int main( int argc, char **argv )
{
struct timeval now_time;
/*
* Kill any outstanding alarm (copyover)
*/
set_alarm (0);
/*
* Memory debugging if needed.
*/
#if defined(MALLOC_DEBUG)
malloc_debug( 2 );
#endif
sysdata.NO_NAME_RESOLVING = TRUE;
sysdata.WAIT_FOR_AUTH = TRUE;
/*
* Init time.
*/
gettimeofday( &now_time, NULL );
secCurrentTime = (time_t) now_time.tv_sec;
secBootTime = time(0);
strcpy( str_boot_time, ctime( &secCurrentTime ) );
/*
* Init boot time.
*/
set_boot_time = &set_boot_time_struct;
set_boot_time->manual = 0;
new_boot_time = update_time(localtime(&secCurrentTime));
/* Copies *new_boot_time to new_boot_struct, and then points
new_boot_time to new_boot_struct again. -- Alty */
new_boot_struct = *new_boot_time;
new_boot_time = &new_boot_struct;
new_boot_time->tm_mday += 1;
if(new_boot_time->tm_hour > 12)
new_boot_time->tm_mday += 1;
new_boot_time->tm_sec = 0;
new_boot_time->tm_min = 0;
new_boot_time->tm_hour = 6;
/* Update new_boot_time (due to day increment) */
new_boot_time = update_time(new_boot_time);
new_boot_struct = *new_boot_time;
new_boot_time = &new_boot_struct;
/* Set reboot time string for do_time */
get_reboot_string();
/*
* Reserve two channels for our use.
*/
if ( ( fpReserve = fopen( NULL_FILE, "r" ) ) == NULL )
{
perror( NULL_FILE );
exit( 1 );
}
if ( ( fpLOG = fopen( NULL_FILE, "r" ) ) == NULL )
{
perror( NULL_FILE );
exit( 1 );
}
/*
* Get the port number.
*/
ListenerPort = 5555;
if ( argc > 1 )
{
if ( !is_number( argv[1] ) )
{
fprintf( stderr, "Usage: %s [port #]\n", argv[0] );
exit( 1 );
}
else if ( ( ListenerPort = atoi( argv[1] ) ) <= 1024 )
{
fprintf( stderr, "Port number must be above 1024.\n" );
exit( 1 );
}
}
// Initialize shared strings.
log_string("Initializing shared strings...");
extern void InitializeSharedStrings();
InitializeSharedStrings();
log_string("...done.");
/*
* Run the game.
*/
gConnectionManager = new ConnectionManager();
if ( argv[2] && argv[2][0] ) {
//int control, control2;
fCopyOver = TRUE;
ListenerDescriptor = atoi(argv[3]);
//control2 = atoi(argv[4]);
gConnectionManager->AddListener(ListenerDescriptor);
//gConnectionManager->AddListener(control2);
} else {
fCopyOver = FALSE;
}
first_account = last_account = NULL;
log_string("Creating World Object");
gTheWorld = new World();
log_string("Initializing World Lua");
if (gTheWorld->initializeLua() == false) {
log_string("Failed to initialize world Lua. Aborting.");
exit(1);
}
// Load up the quest manager
log_string("Creating Quest Manager");
gQuestManager = new QuestManager();
if (!gQuestManager->initialize(QUESTS_FILE)) {
log_string("Failed to initialize quest manager. Aborting.");
exit(1);
}
/*#ifndef DEBUG
log_string("Loading DBXML Database Controller");
MasterDatabase = new DatabaseController();
MasterDatabase->Initialize();
#endif*/
log_string("Booting Database");
gBooting = true;
boot_db();
gBooting = false;
log_string("Initializing socket");
if ( !fCopyOver )
{
ListenerDescriptor = gConnectionManager->CreateListener( ListenerPort );
if ( ListenerDescriptor == -1 )
{
log_string("Could not initiate listener sockets. Aborting.");
exit(1);
}
//gConnectionManager->CreateListener( port + 1 );
}
sprintf( log_buf, "Legends of the Darkstone is ready on port %d.", ListenerPort );
log_string( log_buf );
/* Ok, it served its purpose */
fCopyOver = FALSE;
gGameRunning = true;
traceopen( );
game_loop( );
traceclose( );
/*
* That's all, folks.
*/
log_string("Flushing output.");
gConnectionManager->ForceFlushOutput();
log_string("Output flushed.");
// there's no reason for these to not exist - but hey, whatever
if (gConnectionManager)
{
gTheWorld->LogString("Closing connection manager.");
delete gConnectionManager;
}
gConnectionManager = NULL;
if (MasterDatabase)
{
gTheWorld->LogString("Shutting down database.");
delete MasterDatabase;
}
MasterDatabase = NULL;
if (gTheWorld)
{
gTheWorld->LogString("Closing connection manager.");
delete gTheWorld;
}
gTheWorld = NULL;
log_string( "Closing down shared strings..." );
extern void CloseSharedStrings();
CloseSharedStrings();
log_string( "...done." );
log_string( "Normal termination of game." );
exit( 0 );
return 0;
}
#if 0 /* not used by anyone */
static void SegVio()
{
CHAR_DATA *ch;
char buf[MAX_STRING_LENGTH];
log_string( "SEGMENTATION VIOLATION" );
log_string( lastplayercmd );
for ( ch = first_char; ch; ch = ch->next )
{
sprintf( buf, "%PC: %-20s room: %s", IS_NPC(ch) ? 'N' : ' ',
ch->name, vnum_to_dotted(ch->GetInRoom()->vnum) );
log_string( buf );
}
exit(0);
}
#endif
/*
* LAG alarm! -Thoric
*/
static void caught_alarm(int temp)
{
char buf[MAX_STRING_LENGTH];
bug( "ALARM CLOCK!" );
strcpy( buf, "Alas, the hideous malevolent entity known only as 'Lag' rises once more!\n\r" );
echo_to_all( AT_IMMORT, buf, ECHOTAR_ALL );
/*if ( newdesc )
{
FD_CLR( newdesc, &in_set );
FD_CLR( newdesc, &out_set );
log_string( "clearing newdesc" );
}*/
/* game_loop( );
close( control );
log_string( "Normal termination of game." );
exit( 0 );*/
}
long GetMillisecondsTime()
{
#ifdef unix
struct timeval resultTimeval;
gettimeofday( &resultTimeval, NULL );
// First off... tv_sec is seconds since the Epoch
// this is generally Jan 1st 1970.
// now we don't want to multiply this by 1000, since
// it might overflow... so first, subtract the seconds
// from jan-1-1970 to jan-1-2000
resultTimeval.tv_sec -= 946080000; // 30 years
// convert to milliseconds
return resultTimeval.tv_sec * 1000 + resultTimeval.tv_usec / 1000;
#else
#ifdef WIN_32
// Under Windows, the time is the time since system startup.
// Knowing Billysoft, this'll never be more than 5 minutes *wink*
// but seriously, we don't need to worry about overflow here
return timeGetTime();
#endif
#endif
}
void game_loop( )
{
struct timeval last_time;
time_t last_check = 0;
signal( SIGPIPE, SIG_IGN );
signal( SIGALRM, caught_alarm );
gettimeofday( &last_time, NULL );
secCurrentTime = (time_t) last_time.tv_sec;
nextActionTime = GetMillisecondsTime() + FRAME_TIME;
/* Main loop */
while ( gGameRunning )
{
long currentTime;
currentTime = GetMillisecondsTime();
struct timeval delayTime;
long timeDifference = nextActionTime - currentTime;
if (timeDifference > 0)
{
delayTime.tv_sec = 0;
delayTime.tv_usec = 0;
while (timeDifference >= 1000)
{
delayTime.tv_sec += 1;
timeDifference -= 1000;
}
delayTime.tv_usec = timeDifference * 1000;
}
else
{
delayTime.tv_sec = 0;
delayTime.tv_usec = 0;
}
// Only process sockets if the poll succeeded.
if ( gConnectionManager->PollSockets( delayTime ) == false )
{
gTheWorld->LogBugString("There was an error polling the sockets!");
}
else
{
if ( gConnectionManager->ProcessActiveSockets() == false )
gTheWorld->LogBugString("There was an error processing the selected sockets!");
}
// need to handle waiting input lines here
currentTime = GetMillisecondsTime();
while ( currentTime >= nextActionTime )
{
/*
* Run the game logic.
*/
//printf("Pulse\n\r");
gTheWorld->TimeUnit();
// Update next tick time.
nextActionTime += FRAME_TIME;
// Update current time.
currentTime = GetMillisecondsTime();
// a little kludgy, but whatever
gettimeofday( &last_time, NULL );
secCurrentTime = (time_t) last_time.tv_sec;
}
if ( last_check+(10*60) < secCurrentTime )
{ /* check every 5 minutes, or so */
ACCOUNT_BAN_DATA* pban;
last_check = secCurrentTime;
for ( pban = first_account_ban; pban; pban = pban->next )
{
if ( !IS_SET(pban->flags, ACCOUNT_WAITING) )
continue;
if ( pban->secBanTime + (60 * 60 * 24) < secCurrentTime)
{ /* 24 hours, or so */
ACCOUNT_BAN_DATA* ptmp;
sprintf(log_buf, "Waiting account %s died of old age. Not too late to approve.",
pban->address);
log_string(log_buf);
UNLINK(pban, first_account_ban, last_account_ban, next, prev);
ptmp = pban->prev;
DISPOSE(pban);
pban = ptmp;
save_account_banlist();
}
}
}
}
if ( shell_shutdown )
{
itorSocketId itor;
for ( itor = gTheWorld->GetBeginConnection(); itor != gTheWorld->GetEndConnection(); itor++ )
{
// we know that the world's player connection list only holds player connections IDs,
// so we can safely cast it to PlayerConnection*
PlayerConnection * d = (PlayerConnection *) SocketMap[*itor];
d->SendText("\n\n\n******\n\n\nMUD HAS BEEN REBOOTED FROM THE SHELL\n\n\n******\n\n\n");
}
/* Save all characters before booting. */
{
CHAR_DATA* vch;
AREA_DATA* tarea;
for ( vch = first_char; vch; vch = vch->next )
if ( !IS_NPC( vch ) )
save_char_obj( vch );
for ( tarea = first_build; tarea; tarea = tarea->next )
{
char buf[MAX_STRING_LENGTH];
if ( !IS_SET(tarea->status, AREA_LOADED) )
continue;
sprintf(buf, "%s%s", BUILD_DIR, tarea->filename);
fold_area(tarea, buf, FALSE);
}
}
}
return;
}
void stop_idling( CHAR_DATA *ch )
{
if ( !ch
|| !ch->GetConnection()
|| ch->GetConnection()->ConnectedState != CON_PLAYING
|| !ch->WasInRoomId
|| ch->GetInRoom() != get_room_index( ROOM_VNUM_LIMBO ) )
return;
ch->timer = 0;
char_from_room( ch );
char_to_room( ch, RoomMap[ch->WasInRoomId] );
ch->WasInRoomId = 0;
act( AT_ACTION, "$n has returned from the void.", ch, NULL, NULL, TO_ROOM );
return;
}
/*
* Write to one char.
*/
void send_to_char_nocolor( const char *txt, CHAR_DATA *ch )
{
if ( !ch )
{
bug( "Send_to_char: NULL *ch" );
return;
}
ch->sendText(txt, false);
return;
}
/*
* Same as above, but converts &color codes to ANSI sequences..
*/
void send_to_char_color( const char *txt, Character *ch )
{
ch->sendText(txt, true);
}
void write_to_pager( PlayerConnection *d, const char *txt, int length )
{
/*if ( length <= 0 )
length = strlen(txt);
if ( length == 0 )
return;
if ( !d->pagebuf )
{
d->pagesize = MAX_STRING_LENGTH;
CREATE( d->pagebuf, char, d->pagesize );
}
if ( !d->pagepoint )
{
d->pagepoint = d->pagebuf;
d->pagetop = 0;
d->pagecmd = '\0';
}
if ( d->pagetop == 0 && !d->fcommand )
{
d->pagebuf[0] = '\n';
d->pagebuf[1] = '\r';
d->pagetop = 2;
}
while ( d->pagetop + length >= d->pagesize )
{
if ( d->pagesize > 32000 )
{
bug( "Pager overflow. Ignoring.\n\r" );
d->pagetop = 0;
d->pagepoint = NULL;
DISPOSE(d->pagebuf);
d->pagesize = MAX_STRING_LENGTH;
return;
}
d->pagesize *= 2;
RECREATE(d->pagebuf, char, d->pagesize);
}
strncpy(d->pagebuf+d->pagetop, txt, length);
d->pagetop += length;
d->pagebuf[d->pagetop] = '\0';
return;*/
}
void send_to_pager_nocolor( const char *txt, CHAR_DATA *ch )
{
if ( !ch )
{
bug( "Send_to_pager: NULL *ch" );
return;
}
if ( txt && ch->GetConnection() )
{
PlayerConnection *d = ch->GetConnection();
ch = d->GetOriginalCharacter();
if ( IS_NPC(ch) || !IS_SET(ch->pcdata->flags, PCFLAG_PAGERON) )
{
ch->sendText(txt, false);
return;
}
write_to_pager(d, txt, 0);
}
return;
}
void send_to_pager_color( const char *txt, CHAR_DATA *ch )
{
PlayerConnection *d;
const char *colstr;
const char *prevstr = txt;
char colbuf[20];
int ln;
if ( !ch )
{
bug( "Send_to_pager_color: NULL *ch" );
return;
}
if ( !txt || !ch->GetConnection() )
return;
d = ch->GetConnection();
ch = d->GetOriginalCharacter();
// Ksilyan: it goes to ch no matter what... pager is later
//if ( IS_NPC(ch) || !IS_SET(ch->pcdata->flags, PCFLAG_PAGERON) )
//{
ch->sendText(txt, true);
//send_to_char_color(txt, ch);
return;
//}
while ( (colstr = strpbrk(prevstr, "&^")) != NULL )
{
if ( colstr > prevstr )
write_to_pager(d, prevstr, (colstr-prevstr));
ln = make_color_sequence(colstr, colbuf, d);
if ( ln < 0 )
{
prevstr = colstr+1;
break;
}
else if ( ln > 0 )
write_to_pager(d, colbuf, ln);
prevstr = colstr+2;
}
if ( *prevstr )
write_to_pager(d, prevstr, 0);
return;
}
/*
* Function to strip off the "a" or "an" or "the" or "some" from an object's
* short description for the purpose of using it in a sentence sent to
* the owner of the object. (Ie: an object with the short description
* "a long dark blade" would return "long dark blade" for use in a sentence
* like "Your long dark blade". The object name isn't always appropriate
* since it contains keywords that may not look proper. -Thoric
*/
const char *myobj( OBJ_DATA *obj )
{
if ( !str_prefix("a ", obj->shortDesc_.c_str()) )
return obj->shortDesc_.c_str() + 2;
if ( !str_prefix("an ", obj->shortDesc_.c_str()) )
return obj->shortDesc_.c_str() + 3;
if ( !str_prefix("the ", obj->shortDesc_.c_str()) )
return obj->shortDesc_.c_str() + 4;
if ( !str_prefix("some ", obj->shortDesc_.c_str()) )
return obj->shortDesc_.c_str() + 5;
return obj->shortDesc_.c_str();
}
#if 0 /* Moved to color.h */
void set_char_color( sh_int AType, CHAR_DATA *ch )
{
char buf[16];
CHAR_DATA *och;
if ( !ch || !ch->desc )
return;
och = (ch->desc->original ? ch->desc->original : ch);
if ( !IS_NPC(och) && IS_SET(och->act, PLR_ANSI) )
{
if ( AType == 7 )
strcpy( buf, "\033[m" );
else
sprintf(buf, "\033[0;%d;%s%dm", (AType & 8) == 8,
(AType > 15 ? "5;" : ""), (AType & 7)+30);
write_to_buffer( ch->desc, buf, strlen(buf) );
}
return;
}
void set_pager_color( sh_int AType, CHAR_DATA *ch )
{
char buf[16];
CHAR_DATA *och;
if ( !ch || !ch->desc )
return;
och = (ch->desc->original ? ch->desc->original : ch);
if ( !IS_NPC(och) && IS_SET(och->act, PLR_ANSI) )
{
if ( AType == 7 )
strcpy( buf, "\033[m" );
else
sprintf(buf, "\033[0;%d;%s%dm", (AType & 8) == 8,
(AType > 15 ? "5;" : ""), (AType & 7)+30);
send_to_pager( buf, ch );
ch->desc->pagecolor = AType;
}
return;
}
#endif /* moved to color.c */
/* source: EOD, by John Booth <???> */
void ch_printf_nocolor(CHAR_DATA *ch, const char *fmt, ...)
{
char buf[MAX_STRING_LENGTH*2]; /* better safe than sorry */