TinyMUSH 3.3
TinyMUSH Server
Loading...
Searching...
No Matches
Functions | Variables
bsd.c File Reference

BSD-style network and signal routines. More...

#include "config.h"
#include "constants.h"
#include "typedefs.h"
#include "macros.h"
#include "externs.h"
#include "prototypes.h"
#include <errno.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/msg.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <ctype.h>
#include <signal.h>
Include dependency graph for bsd.c:

Functions

MSGQ_DNSRESOLVER mk_msgq_dnsresolver (const char *addr)
 Convert a text ip address to binary format for the message queue. Not used for now. More...
 
void * dnsResolver (void *args)
 DNS Resolver thread. More...
 
void check_dnsResolver_status (dbref player, __attribute__((unused)) dbref cause, __attribute__((unused)) int key)
 
int make_socket (int port)
 Create a socket. More...
 
void shovechars (int port)
 Process input form a port and feed to the engine. More...
 
DESCnew_connection (int sock)
 Handle new connections. More...
 
char * connReasons (int reason)
 (Dis)connect reasons that get written to the logfile More...
 
char * connMessages (int reason)
 (Dis)connect reasons that get fed to A_A(DIS)CONNECT via announce_connattr More...
 
void shutdownsock (DESC *d, int reason)
 Handle disconnections. More...
 
void make_nonblocking (int s)
 Make a socket nonblocking if needed. More...
 
DESCinitializesock (int s, struct sockaddr_in *a)
 Initialize a socket. More...
 
int process_output (DESC *d)
 Process output to a socket. More...
 
int process_input (DESC *d)
 Process input from a socket. More...
 
void close_sockets (int emergency, char *message)
 Close all sockets. More...
 
void emergency_shutdown (void)
 Suggar we're going down!!! More...
 
void report (void)
 Write a report to log. More...
 
void sighandler (int sig)
 Handle system signals. More...
 
void set_signals (void)
 Set the signals handlers. More...
 
void unset_signals (void)
 Unset the signal handlers. More...
 
void check_panicking (int sig)
 Check if we are panicking. More...
 
void log_signal (const char *signame)
 Log the signal we caugh. More...
 

Variables

int sock = 0
 
int ndescriptors = 0
 
int maxd = 0
 
DESCdescriptor_list = NULL
 
key_t msgq_Key = 0
 Message queue related. More...
 

Detailed Description

BSD-style network and signal routines.

Author
TinyMUSH development team (https://github.com/TinyMUSH)
Version
3.3
Date
2020-12-25
Note
Why should I care what color the bikeshed is? :)

Function Documentation

◆ check_dnsResolver_status()

void check_dnsResolver_status ( dbref  player,
__attribute__((unused)) dbref  cause,
__attribute__((unused)) int  key 
)
Todo:
Just a placeholder for now. Call by @startslave that should also be rename to something better suiting once i sort out what this should do.

◆ check_panicking()

void check_panicking ( int  sig)

Check if we are panicking.

Parameters
sigSignal that triggered the check

If we are panicking, turn off signal catching and resignal

◆ close_sockets()

void close_sockets ( int  emergency,
char *  message 
)

Close all sockets.

Parameters
emergencyClosing caused by emergency?
messageMessage to send before closing

◆ connMessages()

char * connMessages ( int  reason)

(Dis)connect reasons that get fed to A_A(DIS)CONNECT via announce_connattr

Parameters
messagereason ID
Returns
char* reason message

◆ connReasons()

char * connReasons ( int  reason)

(Dis)connect reasons that get written to the logfile

Parameters
reasonreason ID
Returns
char* reason message

◆ dnsResolver()

void * dnsResolver ( void *  args)

DNS Resolver thread.

Parameters
argsMessage queue key
Returns
void* Always null. Not used.

◆ emergency_shutdown()

void emergency_shutdown ( void  )

Suggar we're going down!!!

◆ initializesock()

DESC * initializesock ( int  s,
struct sockaddr_in *  a 
)

Initialize a socket.

Parameters
sSocket file descriptor
aSocket internet address descriptor
Returns
DESC* Connection descriptor

◆ log_signal()

void log_signal ( const char *  signame)

Log the signal we caugh.

Parameters
signameSignal name.

◆ make_nonblocking()

void make_nonblocking ( int  s)

Make a socket nonblocking if needed.

Parameters
sSocket to modify.

◆ make_socket()

int make_socket ( int  port)

Create a socket.

Parameters
portPort for the socket
Returns
int file descriptor of the socket

◆ mk_msgq_dnsresolver()

MSGQ_DNSRESOLVER mk_msgq_dnsresolver ( const char *  addr)

Convert a text ip address to binary format for the message queue. Not used for now.

Parameters
addrIP address
Returns
MSGQ_DNSRESOLVER

◆ new_connection()

DESC * new_connection ( int  sock)

Handle new connections.

Parameters
sockSocket to listen for new connections
Returns
DESC* Connection descriptor

Ask DNS Resolver for hostname

◆ process_input()

int process_input ( DESC d)

Process input from a socket.

Parameters
dSocket description
Returns
int

◆ process_output()

int process_output ( DESC d)

Process output to a socket.

Parameters
dSocket description
Returns
int

◆ report()

void report ( void  )

Write a report to log.

◆ set_signals()

void set_signals ( void  )

Set the signals handlers.

We have to reset our signal mask, because of the possibility that we triggered a restart on a SIGUSR1. If we did so, then the signal became blocked, and stays blocked, since control never returns to the caller; i.e., further attempts to send a SIGUSR1 would fail.

◆ shovechars()

void shovechars ( int  port)

Process input form a port and feed to the engine.

Parameters
portPort to listen

Start the message queue.

Start the DNS resolver thread

Attention
This is the main loop of the MUSH, everything derive from here...

We've gotten a signal to dump flatfiles

test for events

any queued robot commands waiting?

Listen for new connections if there are free descriptors

Mark sockets that we want to test for change in status

Wait for something to happen

This one is bad, as it results in a spiral of doom, unless we can figure out what the bad file descriptor is and get rid of it.

It's a player. Just toss the connection.

We didn't figured it out, well that's it, game over.

if !found then time for robot commands

Check if we have something from the DNS Resolver.

Check for new connection requests

Check for activity on user sockets

Process input from sockets with pending input

Undo AutoDark

Process received data

Process output for sockets with pending output

Stop the DNS message queue.

Wait for the thread to end.

◆ shutdownsock()

void shutdownsock ( DESC d,
int  reason 
)

Handle disconnections.

Parameters
dConnection descriptor
reasonReason for disconnection

Do the disconnect stuff if we aren't doing a LOGOUT (which keeps the connection open so the player can connect to a different character).

If the socket died, there's no reason to display the quit file.

If requested, write an accounting record of the form: Plyr# Flags Cmds ConnTime Loc Money [Site] <DiscRsn> Name

If this was our only connection, get out of interactive mode.

Free_RegData

Free_RegDataStruct

◆ sighandler()

void sighandler ( int  sig)

Handle system signals.

Parameters
sigSignal to handle

< Normal restart now

< Dump a flatfile soon

< Timer

< Change in child status

< Dump database soon

< Force a live backup

< Normal shutdown soon

< Killed shutdown now

< Panic save + restart now, or coredump now

Not good, Don't sync, restart using older db.

Try our best to dump a usable core by generating a second signal with the SIG_DFL action.

In the parent process (easier to follow with gdb), we're about to return from this signal handler and hope that a second signal is delivered. Meanwhile let's close all our files to avoid corrupting the child process.

< Coredump now

◆ unset_signals()

void unset_signals ( void  )

Unset the signal handlers.

Variable Documentation

◆ descriptor_list

DESC* descriptor_list = NULL

Descriptor list

◆ maxd

int maxd = 0

Max Descriptors

◆ msgq_Key

key_t msgq_Key = 0

Message queue related.

Message Queue Key

◆ ndescriptors

int ndescriptors = 0

New Descriptor

◆ sock

int sock = 0
Attention
Since this is the core of the whole show, better keep theses globals. Game socket