Galactic Bloodshed
Classes | Namespaces | Macros | Typedefs | Functions | Variables
GB_server.cc File Reference
#include "gb/GB_server.h"
#include <arpa/inet.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
#include <cctype>
#include <cerrno>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
#include "gb/buffers.h"
#include "gb/build.h"
#include "gb/commands/analysis.h"
#include "gb/commands/autoreport.h"
#include "gb/commands/capital.h"
#include "gb/commands/capture.h"
#include "gb/commands/colonies.h"
#include "gb/commands/dock.h"
#include "gb/commands/enslave.h"
#include "gb/commands/examine.h"
#include "gb/commands/fix.h"
#include "gb/commands/governors.h"
#include "gb/commands/grant.h"
#include "gb/commands/highlight.h"
#include "gb/commands/orbit.h"
#include "gb/commands/production.h"
#include "gb/commands/relation.h"
#include "gb/commands/rst.h"
#include "gb/commands/scrap.h"
#include "gb/commands/tech_status.h"
#include "gb/commands/toggle.h"
#include "gb/commands/toxicity.h"
#include "gb/commands/zoom.h"
#include "gb/config.h"
#include "gb/cs.h"
#include "gb/declare.h"
#include "gb/defense.h"
#include "gb/dissolve.h"
#include "gb/doturncmd.h"
#include "gb/explore.h"
#include "gb/files.h"
#include "gb/files_shl.h"
#include "gb/fire.h"
#include "gb/fuel.h"
#include "gb/globals.h"
#include "gb/land.h"
#include "gb/launch.h"
#include "gb/load.h"
#include "gb/map.h"
#include "gb/mobiliz.h"
#include "gb/move.h"
#include "gb/name.h"
#include "gb/order.h"
#include "gb/power.h"
#include "gb/powercmd.h"
#include "gb/prof.h"
#include "gb/races.h"
#include "gb/ships.h"
#include "gb/shlmisc.h"
#include "gb/sql/sql.h"
#include "gb/survey.h"
#include "gb/tech.h"
#include "gb/tele.h"
#include "gb/tweakables.h"
#include "gb/utils/rand.h"
#include "gb/vars.h"
#include "gb/victory.h"

Go to the source code of this file.

Classes

class  TextBlock
 
class  DescriptorData
 

Namespaces

 anonymous_namespace{GB_server.cc}
 

Macros

#define MAX_COMMAND_LEN   512
 

Typedefs

using CommandFunction = void(*)(const command_t &, GameObj &)
 

Functions

static double GetComplexity (const ShipType)
 
static void set_signals ()
 
static void queue_string (DescriptorData &, const std::string &)
 
static void add_to_queue (std::deque< TextBlock > &, const std::string &)
 
static void help (const command_t &, GameObj &)
 
static void process_command (DescriptorData &, const command_t &argv)
 
static int shovechars (int, Db &)
 
static void GB_time (const command_t &, GameObj &)
 
static void GB_schedule (const command_t &, GameObj &)
 
static void do_update (bool=false)
 
static void do_segment (int, int)
 
static int make_socket (int)
 
static void shutdownsock (DescriptorData &)
 
static void load_race_data ()
 
static void load_star_data ()
 
static void make_nonblocking (int)
 
static struct timeval update_quotas (struct timeval, struct timeval)
 
static int process_output (DescriptorData &)
 
static void welcome_user (DescriptorData &)
 
static int flush_queue (std::deque< TextBlock > &, int)
 
static void process_commands ()
 
static int do_command (DescriptorData &, const char *)
 
static void goodbye_user (DescriptorData &)
 
static void dump_users (DescriptorData &)
 
static void close_sockets (int)
 
static int process_input (DescriptorData &)
 
static void force_output ()
 
static void help_user (GameObj &)
 
static int msec_diff (struct timeval, struct timeval)
 
static struct timeval msec_add (struct timeval, int)
 
static void save_command (DescriptorData &, const std::string &)
 
static void strstr_to_queue (DescriptorData &)
 
static int ShipCompare (const void *, const void *)
 
static void SortShips ()
 
static void check_connect (DescriptorData &, const char *)
 
static struct timeval timeval_sub (struct timeval now, struct timeval then)
 
std::tuple< std::string, std::string > anonymous_namespace{GB_server.cc}::parse_connect (const std::string &message)
 Parse input string for player and governor password. More...
 
std::string anonymous_namespace{GB_server.cc}::do_prompt (DescriptorData &d)
 Create a prompt that shows the current AP and location of the player. More...
 
int main (int argc, char **argv)
 
void notify_race (const player_t race, const std::string &message)
 
bool notify (const player_t race, const governor_t gov, const std::string &message)
 
void d_think (const player_t Playernum, const governor_t Governor, const std::string &message)
 
void d_broadcast (const player_t Playernum, const governor_t Governor, const std::string &message)
 
void d_shout (const player_t Playernum, const governor_t Governor, const std::string &message)
 
void d_announce (const player_t Playernum, const governor_t Governor, const starnum_t star, const std::string &message)
 
void do_next_thing ()
 
void kill_ship (int Playernum, Ship *ship)
 
void compute_power_blocks ()
 
void insert_sh_univ (struct stardata *sdata, Ship *s)
 
void insert_sh_star (startype *star, Ship *s)
 
void insert_sh_plan (Planet *pl, Ship *s)
 
void insert_sh_ship (Ship *s, Ship *s2)
 
void remove_sh_star (Ship &s)
 Remove a ship from the list of ships orbiting the star. More...
 
void remove_sh_plan (Ship &s)
 Remove a ship from the list of ships orbiting the planet. More...
 
void remove_sh_ship (Ship &s, Ship &host)
 Remove a ship from the list of ships in the ship. More...
 
void warn_race (const player_t who, const std::string &message)
 
void warn (const player_t who, const governor_t governor, const std::string &message)
 
void warn_star (const player_t a, const starnum_t star, const std::string &message)
 
void notify_star (const player_t a, const governor_t g, const starnum_t star, const std::string &message)
 
void adjust_morale (Race *winner, racetype *loser, int amount)
 

Variables

static int shutdown_flag = 0
 
static int update_flag = 0
 
static time_t last_update_time
 
static time_t last_segment_time
 
static unsigned int nupdates_done
 
static char start_buf [128]
 
static char update_buf [128]
 
static char segment_buf [128]
 
static std::list< DescriptorDatadescriptor_list
 
static const std::unordered_map< std::string, CommandFunctioncommands
 

Macro Definition Documentation

◆ MAX_COMMAND_LEN

#define MAX_COMMAND_LEN   512

Definition at line 199 of file GB_server.cc.

Typedef Documentation

◆ CommandFunction

using CommandFunction = void (*)(const command_t &, GameObj &)

Definition at line 203 of file GB_server.cc.

Function Documentation

◆ add_to_queue()

static void add_to_queue ( std::deque< TextBlock > &  q,
const std::string &  b 
)
static

Definition at line 793 of file GB_server.cc.

◆ adjust_morale()

void adjust_morale ( Race winner,
racetype loser,
int  amount 
)

Definition at line 1681 of file GB_server.cc.

◆ check_connect()

static void check_connect ( DescriptorData d,
const char *  message 
)
static

Definition at line 1026 of file GB_server.cc.

◆ close_sockets()

static void close_sockets ( int  sock)
static

Definition at line 1217 of file GB_server.cc.

◆ compute_power_blocks()

void compute_power_blocks ( )

Definition at line 1469 of file GB_server.cc.

◆ d_announce()

void d_announce ( const player_t  Playernum,
const governor_t  Governor,
const starnum_t  star,
const std::string &  message 
)

Definition at line 596 of file GB_server.cc.

◆ d_broadcast()

void d_broadcast ( const player_t  Playernum,
const governor_t  Governor,
const std::string &  message 
)

Definition at line 577 of file GB_server.cc.

◆ d_shout()

void d_shout ( const player_t  Playernum,
const governor_t  Governor,
const std::string &  message 
)

Definition at line 587 of file GB_server.cc.

◆ d_think()

void d_think ( const player_t  Playernum,
const governor_t  Governor,
const std::string &  message 
)

Definition at line 567 of file GB_server.cc.

◆ do_command()

static int do_command ( DescriptorData d,
const char *  comm 
)
static

Main processing loop. When command strings are sent from the client, they are processed here. Responses are sent back to the client via notify.

Definition at line 986 of file GB_server.cc.

◆ do_next_thing()

void do_next_thing ( )

Definition at line 728 of file GB_server.cc.

◆ do_segment()

static void do_segment ( int  override,
int  segment 
)
static

Definition at line 1164 of file GB_server.cc.

◆ do_update()

static void do_update ( bool  force = false)
static

Definition at line 1092 of file GB_server.cc.

◆ dump_users()

static void dump_users ( DescriptorData e)
static

Definition at line 1230 of file GB_server.cc.

◆ flush_queue()

static int flush_queue ( std::deque< TextBlock > &  q,
int  n 
)
static

Definition at line 799 of file GB_server.cc.

◆ force_output()

static void force_output ( )
static

Definition at line 859 of file GB_server.cc.

◆ GB_schedule()

static void GB_schedule ( const command_t ,
GameObj g 
)
static

Definition at line 1353 of file GB_server.cc.

◆ GB_time()

static void GB_time ( const command_t ,
GameObj g 
)
static

Definition at line 1342 of file GB_server.cc.

◆ GetComplexity()

static double GetComplexity ( const ShipType  ship)
static

Definition at line 1615 of file GB_server.cc.

◆ goodbye_user()

static void goodbye_user ( DescriptorData d)
static

Definition at line 913 of file GB_server.cc.

◆ help()

static void help ( const command_t argv,
GameObj g 
)
static

Definition at line 1372 of file GB_server.cc.

◆ help_user()

static void help_user ( GameObj g)
static

Definition at line 895 of file GB_server.cc.

◆ insert_sh_plan()

void insert_sh_plan ( Planet pl,
Ship s 
)

Definition at line 1516 of file GB_server.cc.

◆ insert_sh_ship()

void insert_sh_ship ( Ship s,
Ship s2 
)

Definition at line 1522 of file GB_server.cc.

◆ insert_sh_star()

void insert_sh_star ( startype star,
Ship s 
)

Definition at line 1510 of file GB_server.cc.

◆ insert_sh_univ()

void insert_sh_univ ( struct stardata sdata,
Ship s 
)

Definition at line 1504 of file GB_server.cc.

◆ kill_ship()

void kill_ship ( int  Playernum,
Ship ship 
)

Definition at line 1398 of file GB_server.cc.

◆ load_race_data()

static void load_race_data ( )
static

Definition at line 1296 of file GB_server.cc.

◆ load_star_data()

static void load_star_data ( )
static

Definition at line 1310 of file GB_server.cc.

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 445 of file GB_server.cc.

◆ make_nonblocking()

static void make_nonblocking ( int  s)
static

Definition at line 864 of file GB_server.cc.

◆ make_socket()

static int make_socket ( int  port)
static

Definition at line 735 of file GB_server.cc.

◆ msec_add()

static struct timeval msec_add ( struct timeval  t,
int  x 
)
static

Definition at line 623 of file GB_server.cc.

◆ msec_diff()

static int msec_diff ( struct timeval  now,
struct timeval  then 
)
static

Definition at line 618 of file GB_server.cc.

◆ notify()

bool notify ( const player_t  race,
const governor_t  gov,
const std::string &  message 
)

Definition at line 555 of file GB_server.cc.

◆ notify_race()

void notify_race ( const player_t  race,
const std::string &  message 
)

Definition at line 546 of file GB_server.cc.

◆ notify_star()

void notify_star ( const player_t  a,
const governor_t  g,
const starnum_t  star,
const std::string &  message 
)

Definition at line 1672 of file GB_server.cc.

◆ process_command()

static void process_command ( DescriptorData d,
const command_t argv 
)
static

Definition at line 1273 of file GB_server.cc.

◆ process_commands()

static void process_commands ( )
static

Definition at line 956 of file GB_server.cc.

◆ process_input()

static int process_input ( DescriptorData d)
static

Definition at line 922 of file GB_server.cc.

◆ process_output()

static int process_output ( DescriptorData d)
static

Definition at line 832 of file GB_server.cc.

◆ queue_string()

static void queue_string ( DescriptorData d,
const std::string &  b 
)
static

Definition at line 816 of file GB_server.cc.

◆ remove_sh_plan()

void remove_sh_plan ( Ship s)

Remove a ship from the list of ships orbiting the planet.

Definition at line 1563 of file GB_server.cc.

◆ remove_sh_ship()

void remove_sh_ship ( Ship s,
Ship host 
)

Remove a ship from the list of ships in the ship.

Definition at line 1592 of file GB_server.cc.

◆ remove_sh_star()

void remove_sh_star ( Ship s)

Remove a ship from the list of ships orbiting the star.

Definition at line 1534 of file GB_server.cc.

◆ save_command()

static void save_command ( DescriptorData d,
const std::string &  command 
)
static

Definition at line 918 of file GB_server.cc.

◆ set_signals()

static void set_signals ( )
static

Definition at line 544 of file GB_server.cc.

◆ ShipCompare()

static int ShipCompare ( const void *  S1,
const void *  S2 
)
static

Definition at line 1644 of file GB_server.cc.

◆ shovechars()

static int shovechars ( int  port,
Db  
)
static

Definition at line 633 of file GB_server.cc.

◆ shutdownsock()

static void shutdownsock ( DescriptorData d)
static

Definition at line 781 of file GB_server.cc.

◆ SortShips()

static void SortShips ( )
static

Definition at line 1650 of file GB_server.cc.

◆ strstr_to_queue()

static void strstr_to_queue ( DescriptorData d)
static

Definition at line 825 of file GB_server.cc.

◆ timeval_sub()

static struct timeval timeval_sub ( struct timeval  now,
struct timeval  then 
)
static

Definition at line 608 of file GB_server.cc.

◆ update_quotas()

static struct timeval update_quotas ( struct timeval  last,
struct timeval  current 
)
static

Definition at line 768 of file GB_server.cc.

◆ warn()

void warn ( const player_t  who,
const governor_t  governor,
const std::string &  message 
)

Definition at line 1660 of file GB_server.cc.

◆ warn_race()

void warn_race ( const player_t  who,
const std::string &  message 
)

Definition at line 1655 of file GB_server.cc.

◆ warn_star()

void warn_star ( const player_t  a,
const starnum_t  star,
const std::string &  message 
)

Definition at line 1666 of file GB_server.cc.

◆ welcome_user()

static void welcome_user ( DescriptorData d)
static

Definition at line 871 of file GB_server.cc.

Variable Documentation

◆ commands

const std::unordered_map<std::string, CommandFunction> commands
static

Definition at line 205 of file GB_server.cc.

◆ descriptor_list

std::list<DescriptorData> descriptor_list
static

Definition at line 201 of file GB_server.cc.

◆ last_segment_time

time_t last_segment_time
static

Definition at line 95 of file GB_server.cc.

◆ last_update_time

time_t last_update_time
static

Definition at line 94 of file GB_server.cc.

◆ nupdates_done

unsigned int nupdates_done
static

Definition at line 96 of file GB_server.cc.

◆ segment_buf

char segment_buf[128]
static

Definition at line 100 of file GB_server.cc.

◆ shutdown_flag

int shutdown_flag = 0
static

Definition at line 91 of file GB_server.cc.

◆ start_buf

char start_buf[128]
static

Definition at line 98 of file GB_server.cc.

◆ update_buf

char update_buf[128]
static

Definition at line 99 of file GB_server.cc.

◆ update_flag

int update_flag = 0
static

Definition at line 92 of file GB_server.cc.