#include "copyright.h"#include "autoconf.h"#include "config.h"#include "externs.h"#include <sys/file.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <sys/wait.h>#include <signal.h>#include "attrs.h"#include "command.h"#include "file_c.h"#include "slave.h"Include dependency graph for bsd.cpp:

Go to the source code of this file.
Data Structures | |
| struct | SIGNALTYPE |
| struct | MUX_SIGNAMES |
Defines | |
| #define | CheckInput(x) FD_ISSET(x, &input_set) |
| #define | CheckOutput(x) FD_ISSET(x, &output_set) |
| #define | CAST_SIGNAL_FUNC |
Typedefs | |
| typedef struct SIGNALTYPE * | PSIGNALTYPE |
Functions | |
| static void | TelnetSetup (DESC *d) |
| Begin initial telnet negotiations on a socket. | |
| static void | SiteMonSend (int, const char *, DESC *, const char *) |
| static DESC * | initializesock (SOCKET, struct sockaddr_in *) |
| static DESC * | new_connection (PortInfo *Port, int *piError) |
| static bool | process_input (DESC *) |
| static int | make_nonblocking (SOCKET s) |
| void | CleanUpSlaveSocket (void) |
| void | CleanUpSlaveProcess (void) |
| void | boot_slave (dbref executor, dbref caller, dbref enactor, int) |
| Lauch reverse-DNS slave process. | |
| static int | get_slave_result (void) |
| static void | make_socket (PortInfo *Port) |
| void | SetupPorts (int *pnPorts, PortInfo aPorts[], IntArray *pia) |
| bool | ValidSocket (SOCKET s) |
| void | shovechars (int nPorts, PortInfo aPorts[]) |
| void | shutdownsock (DESC *d, int reason) |
| static void | make_nolinger (SOCKET s) |
| static void | config_socket (SOCKET s) |
| void | process_output (void *dvoid, int bHandleShutdown) |
| int | HimState (DESC *d, unsigned char chOption) |
| Return the other side's negotiation state. | |
| int | UsState (DESC *d, unsigned char chOption) |
| Return our side's negotiation state. | |
| static void | SetHimState (DESC *d, unsigned char chOption, int iHimState) |
| Change the other side's negotiation state. | |
| static void | SetUsState (DESC *d, unsigned char chOption, int iUsState) |
| Change our side's negotiation state. | |
| static void | SendWill (DESC *d, unsigned char chOption) |
| Transmit a Telnet WILL sequence for the given option. | |
| static void | SendDont (DESC *d, unsigned char chOption) |
| Transmit a Telnet DONT sequence for the given option. | |
| static void | SendDo (DESC *d, unsigned char chOption) |
| Transmit a Telnet DO sequence for the given option. | |
| static void | SendWont (DESC *d, unsigned char chOption) |
| Transmit a Telnet WONT sequence for the given option. | |
| static bool | DesiredHimOption (DESC *d, unsigned char chOption) |
| Determine whether we want a particular option on his side of the link to be enabled. | |
| static bool | DesiredUsOption (DESC *d, unsigned char chOption) |
| Determine whether we want a particular option on our side of the link to be enabled. | |
| void | EnableHim (DESC *d, unsigned char chOption) |
| Start the process of negotiating the enablement of an option on his side. | |
| void | DisableHim (DESC *d, unsigned char chOption) |
| Start the process of negotiating the disablement of an option on his side. | |
| void | EnableUs (DESC *d, unsigned char chOption) |
| Start the process of negotiating the enablement of an option on our side. | |
| void | DisableUs (DESC *d, unsigned char chOption) |
| Start the process of negotiating the disablement of an option on our side. | |
| static void | process_input_helper (DESC *d, char *pBytes, int nBytes) |
| Parse raw data from network connection into command lines and Telnet indications. | |
| void | close_sockets (bool emergency, char *message) |
| void | emergency_shutdown (void) |
| static void | check_panicking (int sig) |
| static void | unset_signals (void) |
| void | BuildSignalNamesTable (void) |
| static char * | SignalDesc (int iSignal) |
| static void | log_signal (int iSignal) |
| static void | log_signal_ignore (int iSignal) |
| void | LogStatBuf (int stat_buf, const char *Name) |
| static RETSIGTYPE DCL_CDECL | sighandler (int sig) |
| void | set_signals (void) |
| void | list_system_resources (dbref player) |
Variables | |
| PortInfo | aMainGamePorts [MAX_LISTEN_PORTS] |
| int | nMainGamePorts = 0 |
| unsigned int | ndescriptors = 0 |
| DESC * | descriptor_list = NULL |
| int | maxd = 0 |
| pid_t | slave_pid = 0 |
| int | slave_socket = INVALID_SOCKET |
| pid_t | game_pid |
| static const char * | disc_reasons [] |
| static const char * | disc_messages [] |
| static const unsigned char | nvt_input_xlat_table [256] |
| Table to quickly classify characters recieved from the wire with their Telnet meaning. | |
| static const int | nvt_input_action_table [8][14] |
| Table to map current telnet parsing state state and input to specific actions and state changes. | |
| const SIGNALTYPE | aSigTypes [] |
| static MUX_SIGNAMES | signames [NSIG] |
| NAMETAB | sigactions_nametab [] |
Definition in file bsd.cpp.
| #define CAST_SIGNAL_FUNC |
Definition at line 3413 of file bsd.cpp.
Referenced by alarm_signal(), child_signal(), main(), set_signals(), and sighandler().
| #define CheckInput | ( | x | ) | FD_ISSET(x, &input_set) |
Referenced by shovechars().
| #define CheckOutput | ( | x | ) | FD_ISSET(x, &output_set) |
Referenced by shovechars().
| typedef struct SIGNALTYPE * PSIGNALTYPE |
Lauch reverse-DNS slave process.
This spawns the reverse-DNS slave process and creates a socket-oriented, bi-directional communiocation path between that process and this process. Any existing slave process is killed.
| executor | dbref of Executor. | |
| caller | dbref of Caller. | |
| enactor | dbref of Enactor. |
Definition at line 649 of file bsd.cpp.
References CleanUpSlaveProcess(), CleanUpSlaveSocket(), CMuxAlarm::Clear(), DebugTotalSockets, ENDLOG, LOG_ALWAYS, log_number(), log_text(), make_nonblocking(), maxd, MuxAlarm, slave_pid, slave_socket, and STARTLOG.
Referenced by main(), and shovechars().
00650 { 00651 char *pFailedFunc = 0; 00652 int sv[2]; 00653 int i; 00654 int maxfds; 00655 00656 #ifdef HAVE_GETDTABLESIZE 00657 maxfds = getdtablesize(); 00658 #else // HAVE_GETDTABLESIZE 00659 maxfds = sysconf(_SC_OPEN_MAX); 00660 #endif // HAVE_GETDTABLESIZE 00661 00662 CleanUpSlaveSocket(); 00663 CleanUpSlaveProcess(); 00664 00665 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv) < 0) 00666 { 00667 pFailedFunc = "socketpair() error: "; 00668 goto failure; 00669 } 00670 00671 // Set to nonblocking. 00672 // 00673 if (make_nonblocking(sv[0]) < 0) 00674 { 00675 pFailedFunc = "make_nonblocking() error: "; 00676 close(sv[0]); 00677 close(sv[1]); 00678 goto failure; 00679 } 00680 slave_pid = fork(); 00681 switch (slave_pid) 00682 { 00683 case -1: 00684 00685 pFailedFunc = "fork() error: "; 00686 close(sv[0]); 00687 close(sv[1]); 00688 goto failure; 00689 00690 case 0: 00691 00692 // If we don't clear this alarm, the child will eventually receive a 00693 // SIG_PROF. 00694 // 00695 MuxAlarm.Clear(); 00696 00697 // Child. The following calls to dup2() assume only the minimal 00698 // dup2() functionality. That is, the destination descriptor is 00699 // always available for it, and sv[1] is never that descriptor. 00700 // It is likely that the standard defined behavior of dup2() 00701 // would handle the job by itself more directly, but a little 00702 // extra code is low-cost insurance. 00703 // 00704 close(sv[0]); 00705 if (sv[1] != 0) 00706 { 00707 close(0); 00708 if (dup2(sv[1], 0) == -1) 00709 { 00710 _exit(1); 00711 } 00712 } 00713 if (sv[1] != 1) 00714 { 00715 close(1); 00716 if (dup2(sv[1], 1) == -1) 00717 { 00718 _exit(1); 00719 } 00720 } 00721 for (i = 3; i < maxfds; i++) 00722 { 00723 close(i); 00724 } 00725 execlp("bin/slave", "slave", NULL); 00726 _exit(1); 00727 } 00728 close(sv[1]); 00729 00730 slave_socket = sv[0]; 00731 DebugTotalSockets++; 00732 if (make_nonblocking(slave_socket) < 0) 00733 { 00734 pFailedFunc = "make_nonblocking() error: "; 00735 CleanUpSlaveSocket(); 00736 goto failure; 00737 } 00738 if (maxd <= slave_socket) 00739 { 00740 maxd = slave_socket + 1; 00741 } 00742 00743 STARTLOG(LOG_ALWAYS, "NET", "SLAVE"); 00744 log_text("DNS lookup slave started on fd "); 00745 log_number(slave_socket); 00746 ENDLOG; 00747 return; 00748 00749 failure: 00750 00751 CleanUpSlaveProcess(); 00752 STARTLOG(LOG_ALWAYS, "NET", "SLAVE"); 00753 log_text(pFailedFunc); 00754 log_number(errno); 00755 ENDLOG; 00756 }
| void BuildSignalNamesTable | ( | void | ) |
Definition at line 3632 of file bsd.cpp.
References aSigTypes, SIGNALTYPE::iSignal, MUX_SIGNAMES::pLongName, MUX_SIGNAMES::pShortName, signames, and SIGNALTYPE::szSignal.
Referenced by main().
03633 { 03634 int i; 03635 for (i = 0; i < NSIG; i++) 03636 { 03637 signames[i].pShortName = NULL; 03638 signames[i].pLongName = NULL; 03639 } 03640 03641 const SIGNALTYPE *pst = aSigTypes; 03642 while (pst->szSignal) 03643 { 03644 int sig = pst->iSignal; 03645 if ( 0 <= sig 03646 && sig < NSIG) 03647 { 03648 MUX_SIGNAMES *tsn = &signames[sig]; 03649 if (tsn->pShortName == NULL) 03650 { 03651 tsn->pShortName = pst->szSignal; 03652 #ifndef WIN32 03653 if (sig == SIGUSR1) 03654 { 03655 tsn->pLongName = "Restart server"; 03656 } 03657 else if (sig == SIGUSR2) 03658 { 03659 tsn->pLongName = "Drop flatfile"; 03660 } 03661 #endif // WIN32 03662 #ifdef SysSigNames 03663 if ( tsn->pLongName == NULL 03664 && SysSigNames[sig] 03665 && strcmp(tsn->pShortName, SysSigNames[sig]) != 0) 03666 { 03667 tsn->pLongName = SysSigNames[sig]; 03668 } 03669 #endif // SysSigNames 03670 } 03671 } 03672 pst++; 03673 } 03674 for (i = 0; i < NSIG; i++) 03675 { 03676 MUX_SIGNAMES *tsn = &signames[i]; 03677 if (tsn->pShortName == NULL) 03678 { 03679 #ifdef SysSigNames 03680 if (SysSigNames[i]) 03681 { 03682 tsn->pLongName = SysSigNames[i]; 03683 } 03684 #endif // SysSigNames 03685 03686 // This is the only non-const memory case. 03687 // 03688 tsn->pShortName = StringClone(tprintf("SIG%03d", i)); 03689 } 03690 } 03691 }
| static void check_panicking | ( | int | sig | ) | [static] |
Definition at line 3380 of file bsd.cpp.
References game_pid, mudstate, statedata::panicking, and UNUSED_PARAMETER.
Referenced by sighandler().
03381 { 03382 // If we are panicking, turn off signal catching and resignal. 03383 // 03384 if (mudstate.panicking) 03385 { 03386 for (int i = 0; i < NSIG; i++) 03387 { 03388 signal(i, SIG_DFL); 03389 } 03390 #ifdef WIN32 03391 UNUSED_PARAMETER(sig); 03392 abort(); 03393 #else // WIN32 03394 kill(game_pid, sig); 03395 #endif // WIN32 03396 } 03397 mudstate.panicking = true; 03398 }
| void CleanUpSlaveProcess | ( | void | ) |
Definition at line 478 of file bsd.cpp.
References slave_pid.
Referenced by boot_slave(), do_restart(), get_slave_result(), main(), new_connection(), and sighandler().
00479 { 00480 if (slave_pid > 0) 00481 { 00482 kill(slave_pid, SIGKILL); 00483 waitpid(slave_pid, NULL, 0); 00484 } 00485 slave_pid = 0; 00486 }
| void CleanUpSlaveSocket | ( | void | ) |
Definition at line 465 of file bsd.cpp.
References DebugTotalSockets, INVALID_SOCKET, IS_INVALID_SOCKET, SD_BOTH, and slave_socket.
Referenced by boot_slave(), do_restart(), get_slave_result(), main(), new_connection(), and sighandler().
00466 { 00467 if (!IS_INVALID_SOCKET(slave_socket)) 00468 { 00469 shutdown(slave_socket, SD_BOTH); 00470 if (close(slave_socket) == 0) 00471 { 00472 DebugTotalSockets--; 00473 } 00474 slave_socket = INVALID_SOCKET; 00475 } 00476 }
| void close_sockets | ( | bool | emergency, | |
| char * | message | |||
| ) |
Definition at line 3336 of file bsd.cpp.
References aMainGamePorts, DebugTotalSockets, DESC_SAFEITER_ALL, descriptor_data::descriptor, INVALID_SOCKET, IS_SOCKET_ERROR, log_perror(), nMainGamePorts, queue_string(), queue_write_LEN(), R_GOING_DOWN, SD_BOTH, shutdownsock(), PortInfo::socket, SOCKET_CLOSE, and SOCKET_WRITE.
Referenced by emergency_shutdown(), and main().
03337 { 03338 DESC *d, *dnext; 03339 03340 DESC_SAFEITER_ALL(d, dnext) 03341 { 03342 if (emergency) 03343 { 03344 SOCKET_WRITE(d->descriptor, message, strlen(message), 0); 03345 if (IS_SOCKET_ERROR(shutdown(d->descriptor, SD_BOTH))) 03346 { 03347 log_perror("NET", "FAIL", NULL, "shutdown"); 03348 } 03349 if (SOCKET_CLOSE(d->descriptor) == 0) 03350 { 03351 DebugTotalSockets--; 03352 } 03353 } 03354 else 03355 { 03356 queue_string(d, message); 03357 queue_write_LEN(d, "\r\n", 2); 03358 shutdownsock(d, R_GOING_DOWN); 03359 } 03360 } 03361 for (int i = 0; i < nMainGamePorts; i++) 03362 { 03363 if (SOCKET_CLOSE(aMainGamePorts[i].socket) == 0) 03364 { 03365 DebugTotalSockets--; 03366 } 03367 aMainGamePorts[i].socket = INVALID_SOCKET; 03368 } 03369 }
| static void config_socket | ( | SOCKET | s | ) | [static] |
Definition at line 2202 of file bsd.cpp.
References make_nolinger(), and make_nonblocking().
Referenced by initializesock().
02203 { 02204 make_nonblocking(s); 02205 make_nolinger(s); 02206 }
| static bool DesiredHimOption | ( | DESC * | d, | |
| unsigned char | chOption | |||
| ) | [static] |
Determine whether we want a particular option on his side of the link to be enabled.
| d | Player connection context. | |
| chOption | Telnet Option. |
Definition at line 2797 of file bsd.cpp.
References TELNET_EOR, TELNET_NAWS, TELNET_SGA, and UNUSED_PARAMETER.
Referenced by process_input_helper().
02798 { 02799 UNUSED_PARAMETER(d); 02800 02801 if ( TELNET_NAWS == chOption 02802 || TELNET_EOR == chOption 02803 || TELNET_SGA == chOption) 02804 { 02805 return true; 02806 } 02807 return false; 02808 }
| static bool DesiredUsOption | ( | DESC * | d, | |
| unsigned char | chOption | |||
| ) | [static] |
Determine whether we want a particular option on our side of the link to be enabled.
It doesn't make sense for NAWS to be enabled on the server side, and we only negotiate SGA on our side if we have already successfully negotiated the EOR option.
| d | Player connection context. | |
| chOption | Telnet Option. |
Definition at line 2822 of file bsd.cpp.
References OPTION_YES, TELNET_EOR, TELNET_SGA, and UsState().
Referenced by process_input_helper().
02823 { 02824 if ( TELNET_EOR == chOption 02825 || ( TELNET_SGA == chOption 02826 && OPTION_YES == UsState(d, TELNET_EOR))) 02827 { 02828 return true; 02829 } 02830 return false; 02831 }
| void DisableHim | ( | DESC * | d, | |
| unsigned char | chOption | |||
| ) |
Start the process of negotiating the disablement of an option on his side.
Whether we actually send anything across the wire to disable this depends on the negotiation state. The option could potentially already be disabled.
| d | Player connection context. | |
| chOption | Telnet Option. |
Definition at line 2874 of file bsd.cpp.
References HimState(), OPTION_WANTNO_EMPTY, OPTION_WANTNO_OPPOSITE, OPTION_WANTYES_EMPTY, OPTION_WANTYES_OPPOSITE, OPTION_YES, SendDont(), and SetHimState().
02875 { 02876 switch (HimState(d, chOption)) 02877 { 02878 case OPTION_YES: 02879 SetHimState(d, chOption, OPTION_WANTNO_EMPTY); 02880 SendDont(d, chOption); 02881 break; 02882 02883 case OPTION_WANTNO_OPPOSITE: 02884 SetHimState(d, chOption, OPTION_WANTNO_EMPTY); 02885 break; 02886 02887 case OPTION_WANTYES_EMPTY: 02888 SetHimState(d, chOption, OPTION_WANTYES_OPPOSITE); 02889 break; 02890 } 02891 }
| void DisableUs | ( | DESC * | d, | |
| unsigned char | chOption | |||
| ) |
Start the process of negotiating the disablement of an option on our side.
Whether we actually send anything across the wire to disable this depends on the negotiation state. The option could potentially already be disabled.
| d | Player connection context. | |
| chOption | Telnet Option. |
Definition at line 2934 of file bsd.cpp.
References HimState(), OPTION_WANTNO_EMPTY, OPTION_WANTNO_OPPOSITE, OPTION_WANTYES_EMPTY, OPTION_WANTYES_OPPOSITE, OPTION_YES, SendWont(), and SetUsState().
Referenced by SetUsState().
02935 { 02936 switch (HimState(d, chOption)) 02937 { 02938 case OPTION_YES: 02939 SetUsState(d, chOption, OPTION_WANTNO_EMPTY); 02940 SendWont(d, chOption); 02941 break; 02942 02943 case OPTION_WANTNO_OPPOSITE: 02944 SetUsState(d, chOption, OPTION_WANTNO_EMPTY); 02945 break; 02946 02947 case OPTION_WANTYES_EMPTY: 02948 SetUsState(d, chOption, OPTION_WANTYES_OPPOSITE); 02949 break; 02950 } 02951 }
| void emergency_shutdown | ( | void | ) |
Definition at line 3371 of file bsd.cpp.
References close_sockets().
Referenced by do_shutdown().
03372 { 03373 close_sockets(true, "Going down - Bye"); 03374 }
| void EnableHim | ( | DESC * | d, | |
| unsigned char | chOption | |||
| ) |
Start the process of negotiating the enablement of an option on his side.
Whether we actually send anything across the wire to enable this depends on the negotiation state. The option could potentially already be enabled.
| d | Player connection context. | |
| chOption | Telnet Option. |
Definition at line 2844 of file bsd.cpp.
References HimState(), OPTION_NO, OPTION_WANTNO_EMPTY, OPTION_WANTNO_OPPOSITE, OPTION_WANTYES_EMPTY, OPTION_WANTYES_OPPOSITE, SendDo(), and SetHimState().
Referenced by TelnetSetup().
02845 { 02846 switch (HimState(d, chOption)) 02847 { 02848 case OPTION_NO: 02849 SetHimState(d, chOption, OPTION_WANTYES_EMPTY); 02850 SendDo(d, chOption); 02851 break; 02852 02853 case OPTION_WANTNO_EMPTY: 02854 SetHimState(d, chOption, OPTION_WANTNO_OPPOSITE); 02855 break; 02856 02857 case OPTION_WANTYES_OPPOSITE: 02858 SetHimState(d, chOption, OPTION_WANTYES_EMPTY); 02859 break; 02860 } 02861 }
| void EnableUs | ( | DESC * | d, | |
| unsigned char | chOption | |||
| ) |
Start the process of negotiating the enablement of an option on our side.
Whether we actually send anything across the wire to enable this depends on the negotiation state. The option could potentially already be enabled.
| d | Player connection context. | |
| chOption | Telnet Option. |
Definition at line 2904 of file bsd.cpp.
References HimState(), OPTION_NO, OPTION_WANTNO_EMPTY, OPTION_WANTNO_OPPOSITE, OPTION_WANTYES_EMPTY, OPTION_WANTYES_OPPOSITE, SendWill(), and SetUsState().
Referenced by SetUsState(), and TelnetSetup().
02905 { 02906 switch (HimState(d, chOption)) 02907 { 02908 case OPTION_NO: 02909 SetUsState(d, chOption, OPTION_WANTYES_EMPTY); 02910 SendWill(d, chOption); 02911 break; 02912 02913 case OPTION_WANTNO_EMPTY: 02914 SetUsState(d, chOption, OPTION_WANTNO_OPPOSITE); 02915 break; 02916 02917 case OPTION_WANTYES_OPPOSITE: 02918 SetUsState(d, chOption, OPTION_WANTYES_EMPTY); 02919 break; 02920 } 02921 }
| static int get_slave_result | ( | void | ) | [static] |
Definition at line 806 of file bsd.cpp.
References A_LASTIP, A_LASTSITE, descriptor_data::addr, descriptor_data::address, alloc_lbuf, atr_add_raw(), CleanUpSlaveProcess(), CleanUpSlaveSocket(), descriptor_list, ENDLOG, free_lbuf, LBUF_SIZE, LOG_ALWAYS, log_text(), mudconf, descriptor_data::next, descriptor_data::player, slave_socket, SOCKET_EWOULDBLOCK, SOCKET_LAST_ERROR, STARTLOG, tprintf(), confdata::use_hostname, and descriptor_data::username.
Referenced by shovechars().
00807 { 00808 int local_port, remote_port; 00809 DESC *d; 00810 00811 char *buf = alloc_lbuf("slave_buf"); 00812 00813 int len = read(slave_socket, buf, LBUF_SIZE-1); 00814 if (len < 0) 00815 { 00816 int iSocketError = SOCKET_LAST_ERROR; 00817 if ( iSocketError == SOCKET_EAGAIN 00818 || iSocketError == SOCKET_EWOULDBLOCK) 00819 { 00820 free_lbuf(buf); 00821 return -1; 00822 } 00823 CleanUpSlaveSocket(); 00824 CleanUpSlaveProcess(); 00825 free_lbuf(buf); 00826 00827 STARTLOG(LOG_ALWAYS, "NET", "SLAVE"); 00828 log_text("read() of slave result failed. Slave stopped."); 00829 ENDLOG; 00830 00831 return -1; 00832 } 00833 else if (len == 0) 00834 { 00835 free_lbuf(buf); 00836 return -1; 00837 } 00838 buf[len] = '\0'; 00839 00840 char *token = alloc_lbuf("slave_token"); 00841 char *os = alloc_lbuf("slave_os"); 00842 char *userid = alloc_lbuf("slave_userid"); 00843 char *host = alloc_lbuf("slave_host"); 00844 char *p; 00845 if (sscanf(buf, "%s %s", host, token) != 2) 00846 { 00847 goto Done; 00848 } 00849 p = strchr(buf, '\n'); 00850 *p = '\0'; 00851 if (mudconf.use_hostname) 00852 { 00853 for (d = descriptor_list; d; d = d->next) 00854 { 00855 if (strcmp(d->addr, host) != 0) 00856 { 00857 continue; 00858 } 00859 00860 strncpy(d->addr, token, 50); 00861 d->addr[50] = '\0'; 00862 if (d->player != 0) 00863 { 00864 if (d->username[0]) 00865 { 00866 atr_add_raw(d->player, A_LASTSITE, tprintf("%s@%s", 00867 d->username, d->addr)); 00868 } 00869 else 00870 { 00871 atr_add_raw(d->player, A_LASTSITE, d->addr); 00872 } 00873 atr_add_raw(d->player, A_LASTIP, inet_ntoa((d->address).sin_addr)); 00874 } 00875 } 00876 } 00877 00878 if (sscanf(p + 1, "%s %d , %d : %s : %s : %s", 00879 host, 00880 &remote_port, &local_port, 00881 token, os, userid) != 6) 00882 { 00883 goto Done; 00884 } 00885 for (d = descriptor_list; d; d = d->next) 00886 { 00887 if (ntohs((d->address).sin_port) != remote_port) 00888 continue; 00889 strncpy(d->username, userid, 10); 00890 d->username[10] = '\0'; 00891 if (d->player != 0) 00892 { 00893 atr_add_raw(d->player, A_LASTSITE, tprintf("%s@%s", 00894 d->username, d->addr)); 00895 } 00896 } 00897 Done: 00898 free_lbuf(buf); 00899 free_lbuf(token); 00900 free_lbuf(os); 00901 free_lbuf(userid); 00902 free_lbuf(host); 00903 return 0; 00904 }
| int HimState | ( | DESC * | d, | |
| unsigned char | chOption | |||
| ) |
Return the other side's negotiation state.
The negotiation of each optional feature of telnet can be in one of six states (defined in interface.h): OPTION_NO, OPTION_YES, OPTION_WANTNO_EMPTY, OPTION_WANTNO_OPPOSITE, OPTION_WANTYES_EMPTY, and OPTION_WANTYES_OPPOSITE.
An option is only enabled when it is in the OPTION_YES state.
| d | Player connection context. | |
| chOption | Telnet Option |
Definition at line 2629 of file bsd.cpp.
References descriptor_data::nvt_eor_him_state, descriptor_data::nvt_naws_him_state, descriptor_data::nvt_sga_him_state, OPTION_NO, TELNET_EOR, TELNET_NAWS, and TELNET_SGA.
Referenced by DisableHim(), DisableUs(), EnableHim(), EnableUs(), and process_input_helper().
02630 { 02631 if (TELNET_NAWS == chOption) 02632 { 02633 return d->nvt_naws_him_state; 02634 } 02635 else if (TELNET_EOR == chOption) 02636 { 02637 return d->nvt_eor_him_state; 02638 } 02639 else if (TELNET_SGA == chOption) 02640 { 02641 return d->nvt_sga_him_state; 02642 } 02643 return OPTION_NO; 02644 }
Definition at line 2210 of file bsd.cpp.
References statedata::access_list, descriptor_data::addr, descriptor_data::address, alloc_desc, confdata::cmd_quota_max, descriptor_data::command_count, config_socket(), descriptor_data::connected_at, descriptor_data::descriptor, descriptor_list, descriptor_data::doing, descriptor_data::flags, CLinearTimeAbsolute::GetUTC(), descriptor_data::hashnext, descriptor_data::height, descriptor_data::host_info, confdata::idle_timeout, descriptor_data::input_head, descriptor_data::input_lost, descriptor_data::input_size, descriptor_data::input_tail, descriptor_data::input_tot, descriptor_data::last_time, mudconf, mudstate, ndescriptors, descriptor_data::next, descriptor_data::nOption, descriptor_data::nvt_eor_him_state, descriptor_data::nvt_eor_us_state, NVT_IS_NORMAL, descriptor_data::nvt_naws_him_state, descriptor_data::nvt_naws_us_state, descriptor_data::nvt_sga_him_state, descriptor_data::nvt_sga_us_state, OPTION_NO, descriptor_data::output_head, descriptor_data::output_lost, descriptor_data::output_prefix, descriptor_data::output_size, descriptor_data::output_suffix, descriptor_data::output_tail, descriptor_data::output_tot, descriptor_data::player, descriptor_data::prev, descriptor_data::program_data, descriptor_data::quota, descriptor_data::raw_input, descriptor_data::raw_input_at, descriptor_data::raw_input_state, descriptor_data::retries_left, confdata::retry_limit, site_check(), statedata::suspect_list, descriptor_data::timeout, descriptor_data::username, and descriptor_data::width.
Referenced by new_connection().
02211 { 02212 DESC *d; 02213 02214 #ifdef WIN32 02215 // protect adding the descriptor from the linked list from 02216 // any interference from socket shutdowns 02217 // 02218 if (platform == VER_PLATFORM_WIN32_NT) 02219 { 02220 EnterCriticalSection(&csDescriptorList); 02221 } 02222 #endif // WIN32 02223 02224 d = alloc_desc("init_sock"); 02225 02226 #ifdef WIN32 02227 if (platform == VER_PLATFORM_WIN32_NT) 02228 { 02229 LeaveCriticalSection(&csDescriptorList); 02230 } 02231 #endif // WIN32 02232 02233 d->descriptor = s; 02234 d->flags = 0; 02235 d->connected_at.GetUTC(); 02236 d->last_time = d->connected_at; 02237 d->retries_left = mudconf.retry_limit; 02238 d->command_count = 0; 02239 d->timeout = mudconf.idle_timeout; 02240 d->host_info = site_check((*a).sin_addr, mudstate.access_list) 02241 | site_check((*a).sin_addr, mudstate.suspect_list); 02242 02243 // Be sure #0 isn't wizard. Shouldn't be. 02244 // 02245 d->player = 0; 02246 02247 d->addr[0] = '\0'; 02248 d->doing[0] = '\0'; 02249 d->username[0] = '\0'; 02250 config_socket(s); 02251 d->output_prefix = NULL; 02252 d->output_suffix = NULL; 02253 d->output_size = 0; 02254 d->output_tot = 0; 02255 d->output_lost = 0; 02256 d->output_head = NULL; 02257 d->output_tail = NULL; 02258 d->input_head = NULL; 02259 d->input_tail = NULL; 02260 d->input_size = 0; 02261 d->input_tot = 0; 02262 d->input_lost = 0; 02263 d->raw_input = NULL; 02264 d->raw_input_at = NULL; 02265 d->nOption = 0; 02266 d->raw_input_state = NVT_IS_NORMAL; 02267 d->nvt_sga_him_state = OPTION_NO; 02268 d->nvt_sga_us_state = OPTION_NO; 02269 d->nvt_eor_him_state = OPTION_NO; 02270 d->nvt_eor_us_state = OPTION_NO; 02271 d->nvt_naws_him_state = OPTION_NO; 02272 d->nvt_naws_us_state = OPTION_NO; 02273 d->height = 24; 02274 d->width = 78; 02275 d->quota = mudconf.cmd_quota_max; 02276 d->program_data = NULL; 02277 d->address = *a; 02278 strncpy(d->addr, inet_ntoa(a->sin_addr), 50); 02279 d->addr[50] = '\0'; 02280 02281 #ifdef WIN32 02282 // protect adding the descriptor from the linked list from 02283 // any interference from socket shutdowns 02284 // 02285 if (platform == VER_PLATFORM_WIN32_NT) 02286 { 02287 EnterCriticalSection (&csDescriptorList); 02288 } 02289 #endif // WIN32 02290 02291 ndescriptors++; 02292 02293 if (descriptor_list) 02294 { 02295 descriptor_list->prev = &d->next; 02296 } 02297 d->hashnext = NULL; 02298 d->next = descriptor_list; 02299 d->prev = &descriptor_list; 02300 descriptor_list = d; 02301 02302 #ifdef WIN32 02303 // ok to continue now 02304 // 02305 if (platform == VER_PLATFORM_WIN32_NT) 02306 { 02307 LeaveCriticalSection (&csDescriptorList); 02308 02309 d->OutboundOverlapped.hEvent = NULL; 02310 d->InboundOverlapped.hEvent = NULL; 02311 d->InboundOverlapped.Offset = 0; 02312 d->InboundOverlapped.OffsetHigh = 0; 02313 d->bWritePending = false; // no write pending yet 02314 d->bConnectionShutdown = false; // not shutdown yet 02315 d->bConnectionDropped = false; // not dropped yet 02316 d->bCallProcessOutputLater = false; 02317 } 02318 #endif // WIN32 02319 return d; 02320 }
| void list_system_resources | ( | dbref | player | ) |
Definition at line 4070 of file bsd.cpp.
References DebugTotalFiles, DebugTotalSockets, and notify.
Referenced by do_list().
04071 { 04072 char buffer[80]; 04073 04074 int nTotal = 0; 04075 notify(player, "System Resources"); 04076 04077 sprintf(buffer, "Total Open Files: %ld", DebugTotalFiles); 04078 notify(player, buffer); 04079 nTotal += DebugTotalFiles; 04080 04081 sprintf(buffer, "Total Sockets: %ld", DebugTotalSockets); 04082 notify(player, buffer); 04083 nTotal += DebugTotalSockets; 04084 04085 #ifdef WIN32 04086 sprintf(buffer, "Total Threads: %ld", DebugTotalThreads); 04087 notify(player, buffer); 04088 nTotal += DebugTotalThreads; 04089 04090 sprintf(buffer, "Total Semaphores: %ld", DebugTotalSemaphores); 04091 notify(player, buffer); 04092 nTotal += DebugTotalSemaphores; 04093 #endif // WIN32 04094 04095 sprintf(buffer, "Total Handles (sum of above): %d", nTotal); 04096 notify(player, buffer); 04097 04098 #ifdef WIN32 04099 for (int i = 0; i < NUM_SLAVE_THREADS; i++) 04100 { 04101 sprintf(buffer, "Thread %d at line %u", i+1, SlaveThreadInfo[i].iDoing); 04102 notify(player, buffer); 04103 } 04104 #endif // WIN32 04105 }