-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.cpp
executable file
·860 lines (727 loc) · 20.3 KB
/
connection.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
/*=-=-=-=-=-=-=-=\***********************************************************\
| K ~ M U D | An online, interactive text-based adventure. *
\*-=-=-=-=-=-=-=-/ *
* Written and designed by David "Ksilyan" Haley (c) 2001-2003 *
* All code below is the property of David Haley. The Legends of the *
* Darkstone is granted perpetual usage rights to this code. *
****************************************************************************
* Player Connection Code (see socket_connection) *
\****************************************************************************/
#include "globals.h"
#include "mud.h"
#include "character.h"
#include "connection.h"
#include "mxp.h"
#include "World.h"
#include "connection_manager.h"
#ifdef unix
#include <unistd.h>
#include <arpa/inet.h>
#include <arpa/telnet.h>
#else
#ifdef WIN32
#include <io.h>
#endif
#endif
// STL includes
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
using namespace std;
// Forward declaration
void do_help(Character * ch, const char* argument);
/*
_____ __ __ ____
/ ___/___ ___ ___ / /_ ____ __ __ ____ / /_ ___ ____ / __/___
/ /__ / _ \ / _ \ (_-</ __// __// // // __// __// _ \ / __/ > _/_ _/
\___/ \___//_//_//___/\__//_/ \_,_/ \__/ \__/ \___//_/ |_____/
___ __ __
/ _ \ ___ ___ / /_ ____ __ __ ____ / /_ ___ ____
/ // // -_)(_-</ __// __// // // __// __// _ \ / __/
/____/ \__//___/\__//_/ \_,_/ \__/ \__/ \___//_/
*/
PlayerConnection::PlayerConnection(int descriptor)
{
FileDescriptor = descriptor;
//OutputBuffer = InputBuffer = "";
//InputLine = "";
LastLine = "";
Port = 0;
Host = User = "";
OutputLength = 0;
OutputBuffer.assign("");
UsingMXP = InCommand = false;
Account = NULL;
ConnectedState = CON_GET_EMAIL;
PreviousColor = 0x07;
auth_fd = -1;
pagecolor = 0;
auth_inc = auth_state = 0;
//auth_fd = 0;
atimes = 0;
newstate = 0;
prevcolor = 0;
InPrompt = false;
IdleTime = 0;
OldInputReceiver = NULL;
pager_ = NULL;
LastWrite = secCurrentTime;
Snooping.clear();
}
PlayerConnection::~PlayerConnection()
{
char log_buf[MAX_INPUT_LENGTH];
sprintf( log_buf, "Disconnect: %s", Address.c_str() );
log_string_plus( log_buf, LOG_COMM, sysdata.log_level );
if ( Account ) {
free_account_data(Account);
}
//if (Account)
//delete Account;
if ( FileDescriptor > 0 )
close (FileDescriptor);
//gTheWorld->Connections.remove(this);
}
/*
___ __ _
/ _ \ ___ / / __ __ ___ _ ___ _ (_)___ ___ _
/ // // -_)/ _ \/ // // _ `// _ `// // _ \/ _ `/
/____/ \__//_.__/\_,_/ \_, / \_, //_//_//_/\_, /
/___/ /___/ /___/
*/
void PlayerConnection::Initialize()
{
BAN_DATA * pban;
extern HELP_DATA *curr_greeting; // db.cpp
if (Host.length() > 0)
sprintf( log_buf, "Connection: %s (%s)", Address.c_str(), Host.c_str() );
else
sprintf( log_buf, "Connection: %s", Address.c_str() );
log_string_plus( log_buf, LOG_COMM, sysdata.log_level );
// Kick off the bad boys
for ( pban = first_ban; pban; pban = pban->next )
{
// This used to use str_suffix, but in order to do bans by the
// first part of the ip, ie "ban 207.136.25" str_prefix must
// be used. -- Narn
if ( (!str_prefix( pban->site, GetHost() )|| !str_suffix(pban->site, GetHost())) )
{
SendText(
"\r\r\n\nYour site has been banned from this Mud.\r\n\r\n" );
sprintf(log_buf, "Dropping banned site %s (rule: %s).", GetHost(), pban->site);
gTheWorld->LogCommString(log_buf);
gConnectionManager->RemoveSocket(this, false);
//free_desc( dnew );
set_alarm( 0 );
return;
}
}
/*
* Send the greeting.
*/
if (curr_greeting->text[0] == '.')
SendText( curr_greeting->text + 1);
else
SendText( curr_greeting->text);
curr_greeting = curr_greeting->next;
/* telnet negotiation to see if they support MXP */
this->SendText((const char *) will_mxp_str);
ConnectedState = CON_GET_EMAIL;
SendText("\r\nEnter your email address, or NEW if you are new here: ");
//start_auth( this ); // Start username authorization
set_alarm(0);
gTheWorld->AddConnection(this);
}
Character * PlayerConnection::GetCharacter() const
{
if ( CurrentCharId == 0 )
return NULL;
else
{
Character * result = CharacterMap[CurrentCharId];
if ( result )
return result;
else
{
gTheWorld->LogBugString(
"PlayerConnection::GetCharacter() invalid CurrentChar reference! Char: " + this->codeGetBasicInfo() );
return NULL;
}
}
}
Character * PlayerConnection::GetOriginalCharacter()
{
if ( OriginalCharId == 0 )
return this->GetCharacter(); // no original, so just send current char
else
{
Character * result = CharacterMap[OriginalCharId];
if ( result )
return result;
else
{
gTheWorld->LogBugString(
"PlayerConnection::GetOriginalCharacter() invalid OriginalCharId reference! Char: " + this->codeGetBasicInfo() );
return NULL;
}
}
}
bool PlayerConnection::IsSnooping(Character * ch)
{
if ( !ch )
return false;
idCharacter id = ch->GetId();
if ( find(Snooping.begin(), Snooping.end(), id) == Snooping.end() )
return false;
else
return true;
}
bool PlayerConnection::IsSnooping(idCharacter id)
{
if ( find(Snooping.begin(), Snooping.end(), id) == Snooping.end() )
return false;
else
return true;
}
void PlayerConnection::StartSnooping(Character * ch)
{
if ( !ch )
return;
Snooping.push_back(ch->GetId());
}
void PlayerConnection::CancelSnoop(Character * ch)
{
if ( !ch )
return;
itorCharacterId itor;
list<idCharacter> localList;
localList = Snooping;
for ( itor = localList.begin(); itor != localList.end(); itor++ )
{
if ( *itor == ch->GetId() )
{
ch->StopSnoopedBy(this);
Snooping.remove( ch->GetId() );
}
}
}
void PlayerConnection::CancelAllSnoops()
{
itorCharacterId itor;
for ( itor = Snooping.begin(); itor != Snooping.end(); itor++ )
{
Character * ch = CharacterMap[*itor];
if ( ch )
ch->StopSnoopedBy(this);
}
Snooping.clear();
}
void PlayerConnection::SendText(const char * text, unsigned int textLength)
{
// Create pager, if necessary.
Character * character;
character = GetOriginalCharacter();
if ( character && !IS_NPC(character) && character->pcdata)
{
if ( IS_SET(character->pcdata->flags, PCFLAG_PAGERON) )
{
// The player wants a pager, so create it if necessary
if (!pager_)
pager_ = new Pager(character->pcdata->pagerlen);
else
pager_->SetLineLimit(character->pcdata->pagerlen); // update just in case
}
else
{
// The player does NOT want a pager, so if it exists, delete it.
if (pager_)
delete pager_;
pager_ = NULL;
}
}
// Translate MXP tags if needed.
char * buf;
int lengthToSend = (textLength <= 0 ? strlen(text) : textLength);
int realLength = lengthToSend + count_mxp_tags( UsingMXP, text, lengthToSend );
// Add 1 for trailing zero.
buf = (char *) malloc(realLength + 1);
memset(buf, 0, realLength + 1);
convert_mxp_tags( UsingMXP, buf, text, lengthToSend );
// don't send only \r to the pager, send it directly
// to the connection
if (pager_ && strcmp(text, "\r") )
{
// Add an initial newline, if the buffer is empty
// and we're not processing a command.
if (pager_->BufferSize() == 0 && (!InCommand && !InPrompt))
pager_->AddToBuffer("\r\n");
// Forward output to pager
pager_->AddToBuffer(buf);
}
else
{
// Add an initial newline, if the buffer is empty
// and we're not processing a command.
if (OutputLength == 0 && (!InCommand && !InPrompt))
{
OutputBuffer.append("\r\n");
OutputLength += 2;
}
OutputBuffer.append(buf);
OutputLength += realLength;
}
// Free the temporary storage
free(buf);
}
bool PlayerConnection::WantsToWrite()
{
if (pager_)
return ( OutputLength > 0 || pager_->WantsToWrite() );
else
return (OutputLength > 0);
}
bool PlayerConnection::InOutSet()
{
// Redirect input, if it hasn't been redirected already
if (pager_)
{
if (!OldInputReceiver)
{
OldInputReceiver = InputReceiver;
SetInputReceiver(pager_);
}
// Get next set of output, and
// add it to the connection's buffer
// If we're waiting for user input, this will be empty.
OutputBuffer.append(pager_->GetNextOutput());
OutputLength = OutputBuffer.length();
}
// Return false in case output goes wrong.
// The socket manager will remove the socket,
// so here we only want to save the character.
if ( !SocketConnection::InOutSet() )
{
if ( GetCharacter()
&& ( ConnectedState == CON_PLAYING
|| ConnectedState == CON_EDITING ) )
save_char_obj( GetCharacter() );
return false;
}
LastWrite = secCurrentTime;
// reset input back to the old input receiver, if pager has
// been processed...
if (pager_)
{
if ( pager_->BufferEmpty() )
{
if (OldInputReceiver)
{
SetInputReceiver(OldInputReceiver);
OldInputReceiver = NULL;
}
pager_->ResetLineCount();
}
}
// normally we only arrive here if there was something to write.
// so, if the buffer is empty now... that means that it was emptied
// on this go.
if ( !WantsToWrite() && (this->GetCharacter() != NULL) )
GetCharacter()->OutputBufferEmptied();
return true;
}
bool PlayerConnection::InInSet()
{
// First thing, reset idle time
IdleTime = 0;
if ( GetCharacter() )
GetCharacter()->timer = 0;
// Read from the socket into
// InputBuffer.
if ( !SocketConnection::InInSet() )
{
if ( GetCharacter()
&& ( ConnectedState == CON_PLAYING
|| ConnectedState == CON_EDITING ) )
save_char_obj( GetCharacter() );
return false;
}
// Look for incoming telnet negotiation.
const char * buffer = InputBuffer.c_str();
unsigned char * p;
for (p = (unsigned char *) buffer; *p; p++)
{
if ( *p == IAC )
{
if (memcmp (p, do_mxp_str, strlen ((const char*) do_mxp_str)) == 0)
{
EnableMXP();
/* remove string from input buffer */
InputBuffer.assign( (char *) p + strlen ((const char*) do_mxp_str));
} /* end of turning on MXP */
else if (memcmp (p, dont_mxp_str, strlen ((const char*)dont_mxp_str)) == 0)
{
UsingMXP = false;
/* remove string from input buffer */
InputBuffer.assign( (char *) p + strlen ((const char*) dont_mxp_str));
} /* end of turning off MXP */
}
}
return true;
}
void PlayerConnection::ProcessInputBuffer()
{
// Check to see if character has wait time...
// If so, bail out.
// TODO: round time system controlled by character,
// not connection
if (GetCharacter() && GetCharacter()->GetWait() > 0)
{
return;
}
// Process as long as we have newlines in the input buffer.
while ( FindLine() )
{
if ( InputLine == "" )
continue; // don't bother treating an empty string
// Handle input spamming.
// if length > 1, or if we're trying to repeat the command
if ( InputLine.length() > 1 || !InputLine.compare("!") )
{
// if input line is NOT a repeat request, AND
// input line is not equal to last line...
if ( InputLine.compare("!") && InputLine.compare(LastLine) )
{
RepeatTimes = 0;
}
else
{
if ( GetCharacter() && GetCharacter()->IsFighting() )
--RepeatTimes;
if ( ++RepeatTimes >= 20 )
{
sprintf( log_buf, "%s input spamming (%s)!", GetHost(), InputLine.c_str() );
log_string( log_buf );
SendText("\r\n*** PUT A LID ON IT!!! ***\r\n");
// Instead of having them quit - which can be exploited -
// we have them go link-dead, which is arguably worse
gConnectionManager->RemoveSocket(this, false);
InputBuffer = ""; // clear the input buffer
//strcpy( d->incomm, "quit forcemetoquit" );
}
}
}
/*
* Do '!' substitution.
*/
if ( InputLine.compare("!") == 0 )
InputLine = LastLine;
else
LastLine = InputLine;
//fcommand = true;
stop_idling( GetCharacter() );
//strcpy( cmdline, d->incomm );
//d->incomm[0] = '\0';
if ( GetCharacter() )
{
set_cur_char( GetCharacter() );
trace(GetCharacter(),InputLine.c_str()); /* send to system trace */
}
else
{
trace(NULL,(ConnectedState == CON_GET_OLD_PASSWORD ? "<password hidden>" : InputLine.c_str()));
}
// forward the line to the receiver
InCommand = true;
SendLineToReceiver(InputLine);
InCommand = false;
// Check to see if character has wait time after commands...
// If so, bail out.
// TODO: round time system controlled by character,
// not connection
if (GetCharacter() && GetCharacter()->GetWait() > 0)
break;
// the following should be handled automatically according
// to what InputHandler we have
/*if ( d->pagepoint )
set_pager_input(d, cmdline);
else
{
switch( d->connected )
{
default:
nanny( d, cmdline );
break;
case CON_PLAYING:
interpret( d->character, cmdline );
break;
case CON_EDITING:
edit_buffer( d->character, cmdline );
break;
}
}*/
}
}
bool PlayerConnection::InExcSet()
{
if ( GetCharacter()
&& ( ConnectedState == CON_PLAYING || ConnectedState == CON_EDITING )
)
{
save_char_obj( GetCharacter() );
}
//close_socket( d, TRUE );
return true;
}
void PlayerConnection::EnableMXP()
{
UsingMXP = true;
SendText( (const char*) start_mxp_str );
SendText( MXPMODE (6) ); /* permanent secure mode */
// If we're logging in, send a username request.
if ( ConnectedState == CON_GET_EMAIL )
{
// Send the MXP username request.
SendText( MXPTAG("username") );
}
SendText( MXPTAG ("!-- Set up MXP elements --") );
// Exit tag
SendText( MXPTAG ("!ELEMENT Ex \"<send hint='Click to follow this exit'>\" FLAG=RoomExit") );
// Door
SendText( MXPTAG
( "!ELEMENT ExDoor \"<send href='"
"&text;|"
"close &text;|"
"open &text;|"
"lock &text;"
"unlock &text;"
"' "
"hint='Right-click for door options|"
"Go through door|"
"Close the door|"
"Open the door|"
"Lock the door|"
"Unlock the door"
"'>\" FLAG=RoomExit"
) );
/* Room description tag */
SendText( MXPTAG ("!ELEMENT rdesc '<p>' FLAG=RoomDesc") );
/* Quest tag */
SendText( MXPTAG(
"!ELEMENT ShowQuestItem \"<send href='"
"showquest &text;"
"' "
"hint='More details on this quest'"
">\""
) );
/* Get an item tag (for things on the ground) */
SendText( MXPTAG
("!ELEMENT Get \"<send href='"
"get '&name;'|"
"examine '&name;'|"
"drink '&name;'"
"' "
"hint='RH mouse click to use this object|"
"Get &desc;|"
"Examine &desc;|"
"Drink from &desc;"
"'>\" ATT='name desc'") );
/* Drop an item tag (for things in the inventory) */
SendText( MXPTAG
("!ELEMENT Drop \"<send href='"
"drop '&name;'|"
"examine '&name;'|"
"look in '&name;'|"
"wear '&name;'|"
"eat '&name;'|"
"drink '&name;'"
"' "
"hint='RH mouse click to use this object|"
"Drop &desc;|"
"Examine &desc;|"
"Look inside &desc;|"
"Wear &desc;|"
"Eat &desc;|"
"Drink &desc;"
"'>\" ATT='name desc'") );
/* Bid an item tag (for things in the auction) */
SendText( MXPTAG
("!ELEMENT Bid \"<send href='bid '&name;'' "
"hint='Bid for &desc;'>\" "
"ATT='name desc'") );
/* List an item tag (for things in a shop) */
SendText( MXPTAG
("!ELEMENT List \"<send href='buy '&name;'' "
"hint='Buy &desc;'>\" "
"ATT='name desc'") );
/* Player tag (for who lists, tells etc.) */
SendText( MXPTAG
("!ELEMENT Player \"<send href='tell '&name;' ' "
"hint='Send a message to &name;' prompt>\" "
"ATT='name'") );
}
void PlayerConnection::ShowMotd( )
{
Character *ch;
ch = GetCharacter();
if ( IS_SET(ch->act, PLR_RIP) )
send_rip_screen(ch);
if ( IS_SET(ch->act, PLR_ANSI) )
send_to_pager( "\033[2J", ch ); // this is a clearscreen command.
else
send_to_pager( "\014", ch );
set_pager_color( AT_LBLUE, ch );
if ( IS_IMMORTAL(ch) )
do_help( ch, "imotd" );
if ( IS_HERO(ch) )
do_help( ch, "amotd" );
if ( ch->level < LEVEL_HERO_MIN && ch->level > 0 )
do_help( ch, "motd" );
if ( ch->level == 0 )
do_help( ch, "nmotd" );
send_to_pager( "\r\nPress [ENTER] ", ch );
ConnectedState = CON_READ_MOTD;
}
void PlayerConnection::WriteMainMenu()
{
SendText("Choose your action:\r\n");
SendText("\r\n");
SendText(" 1) Change your account password.\r\n");
SendText(" 2) Read the MOTD.\r\n");
SendText(" 3) Play an existing character.\r\n");
SendText(" 4) Create a new character.\r\n");
SendText(" 5) Delete an existing character.\r\n");
SendText(" 6) Quit Legends of the Darkstone.\r\n");
SendText("\r\n");
SendText("Which sounds good to you? (1,2,3,4,5,6) ");
}
bool PlayerConnection::IsWriteTimingOut()
{
if ( this->WantsToWrite() )
{
if ( secCurrentTime - this->LastWrite > 180 )
{
return true;
}
}
return false;
}
void PlayerConnection::AddIdle()
{
IdleTime++;
// If we have data to write, and the last successful write
// was more than three minutes ago, kill the socket.
if ( this->IsWriteTimingOut() )
{
string buf;
buf = "Account " + string(Account->email) + " timed out";
buf += " (last successful write over three minutes ago.)";
gTheWorld->LogCommString(buf);
// Remove immediately, since waiting won't
// clear the buffer
gConnectionManager->RemoveSocket(this, true);
}
else
{
// If there is nothing to write, set last
// time to now so that we don't get disconnected.
this->LastWrite = secCurrentTime;
}
if ( !GetCharacter() )
{
if (GetIdleSeconds() > 120) // 2 minutes
{
SendText( "Idle timeout... disconnecting.\r\n" );
string buf;
if (Account)
{
buf = "Account ";
buf.append(Account->email);
}
else
{
buf = "Unknown connection";
}
buf.append(" timed out.");
gTheWorld->LogCommString(buf);
gConnectionManager->RemoveSocket(this, false);
}
}
else
{
if ( IS_IMMORTAL(GetCharacter()) )
return; // immortals can't timeout
if ( (ConnectedState != CON_PLAYING && GetIdleSeconds() > 300) // 5 minutes
|| GetIdleSeconds() > 7200) // 2 hours
{
SendText( "Idle timeout... disconnecting.\r\n" );
string buf = "Character ";
buf.append(GetCharacter()->getName().str());
buf.append(" (");
buf.append(Account->email);
buf.append(") timed out.");
gTheWorld->LogCommString(buf);
gConnectionManager->RemoveSocket(this, false);
}
}
}
// Returns the idle time, in seconds.
short PlayerConnection::GetIdleSeconds() const
{
// IdleTime is in clock ticks.
// Clock ticks come every FRAME_TIME milliseconds...
// so...
// seconds = clockticks * (clockticks per second)
// rearranged order for rounding
return (short) ( (FRAME_TIME * 0.001) * IdleTime );
}
short PlayerConnection::GetIdleTicks() const
{
return IdleTime;
}
////////////////////////
// Code object interface
////////////////////////
const string PlayerConnection::codeGetClassName() const
{
return "PlayerConnection";
}
const string PlayerConnection::codeGetBasicInfo() const
{
// for copying results into
ostringstream os;
os << "Desc #" << this->GetDescriptor() << ".";
if (GetCharacter())
os << " Char: " << GetCharacter()->getName().str() << ".";
else
os << " No char.";
if (Account)
os << " Account: " << Account->email << ".";
else
os << " No account.";
os << " Pending: " << OutputLength << " outbound, " <<
InputBuffer.length() << " inbound.";
return os.str();
}
const string PlayerConnection::codeGetFullInfo() const
{
// for copying results into
ostringstream os;
os << "Player connection:" << endl;
os << "Opened on port " << this->GetPort() <<
", descriptor #" << this->GetDescriptor() << "." << endl;
os << "Connection state: " << this->ConnectedState <<
", idle time: " << this->GetIdleTicks() << " (" << this->GetIdleSeconds() << " seconds)" << endl;
if (GetCharacter())
os << "Current character: " << GetCharacter()->getName().str() << endl;
else
os << "No current character." << endl;
if (Account)
os << "Account: " << Account->email <<
", with " << Account->iref << " reference(s)." << endl;
else
os << "No account loaded." << endl;
os << OutputLength << " bytes waiting to be written." << endl;
os << InputBuffer.length() << " bytes in input buffer." << endl;
return os.str();
}