Bugz Door Project
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
door::Door Class Reference

#include <door.h>

Inheritance diagram for door::Door:
Inheritance graph
[legend]
Collaboration diagram for door::Door:
Collaboration graph
[legend]

Public Member Functions

 Door (std::string dname, int argc, char *argv[])
 Construct a new Door:: Door object. More...
 
 Door (Door &)=delete
 
ofstream & log (void)
 Give ofstream handle for logging. More...
 
signed int getkey (void)
 Get a key routine. More...
 
bool haskey (void)
 Are there any keys in STDIN? More...
 
signed int sleep_key (int secs)
 Waits secs seconds for a keypress. More...
 
signed int sleep_ms_key (int msecs)
 Waits miliseconds for a keypress. More...
 
std::string input_string (int max)
 Input a string of requested max length. More...
 
int get_one_of (const char *keys)
 Get one of these keys. More...
 

Public Attributes

AnyOption opt
 
std::string debug_buffer
 
ANSIColor previous
 
bool track
 
int cx
 
int cy
 
int width
 
int height
 
int inactivity
 Number of seconds before timing out. More...
 
std::string username
 
std::string handle
 
std::string location
 
std::string sysop
 
int node
 
atomic< int > time_left
 
atomic< int > time_used
 

Private Member Functions

std::streamsize xsputn (const char *s, std::streamsize n) override
 
int overflow (int c) override
 
void parse_dropfile (const char *filepath)
 Load dropfile into dropfilelines and parse. More...
 
void init (void)
 
signed int getch (void)
 low level read key. More...
 
signed int getkey_or_pushback (void)
 
void detect_unicode_and_screen (void)
 Detect unicode/CP437, and screen size. More...
 
void time_thread_run (std::future< void > future)
 

Private Attributes

std::string doorname
 
std::time_t startup
 
struct termios tio_default
 
bool has_dropfile
 
bool debugging
 
std::string dropfilename
 
vector< std::string > dropfilelines
 
ofstream logf
 
std::promise< void > stop_thread
 
int seconds_elapsed
 
std::thread time_thread
 

Detailed Description

This handles output to the caller, via ostream.

Examples
menu-example.cpp.

Constructor & Destructor Documentation

◆ Door()

door::Door::Door ( std::string  dname,
int  argc,
char *  argv[] 
)

Construct a new Door:: Door object.

Parameters
[in]dnameDoor name used for logfile
[in]argc
[in]argv

Member Function Documentation

◆ detect_unicode_and_screen()

void door::Door::detect_unicode_and_screen ( void  )
private

Detect unicode/CP437, and screen size.

This sets unicode and full_cp437 flags, width and height.

This works by clearing the screen and homing the cursor. We then output some CP437 symbols and ask for the cursor position. We send a newline, output a unicode symbol, and query cursor position.

The CP437 symbols we use are specific. They are the hearts and diamonds symbols, which are commonly mistaken for control codes. If unicode == false and full_cp437 == true, then we do fully support CP437 on this terminal.

For the screensize, we move the cursor down 999 and move cursor right 999 and query position.

On failure to detect screensize, width and height are set to 0.

◆ get_one_of()

int door::Door::get_one_of ( const char *  keys)

Get one of these keys.

returns char, or < 0 if timeout.

Parameters
keys
Returns
char or < 0

◆ getch()

signed int door::Door::getch ( void  )
private

low level read key.

Returns key, or -1 no key available/timeout -2 read error/hang up -3 out of time

Returns
signed int

◆ getkey()

signed int door::Door::getkey ( void  )

Get a key routine.

This returns the key received, or XKEY_* values for function keys, etc. If return < 0: -1 timeout/no key -2 hangup -3 out of time

Returns
signed int

◆ getkey_or_pushback()

signed int door::Door::getkey_or_pushback ( void  )
private

Call low level getch if the pushback buffer is empty.

This allows testing of the Door::getkey function.

Returns
signed int

◆ haskey()

bool door::Door::haskey ( void  )

Are there any keys in STDIN?

This uses select to check if we have received any keys. This does not use pushback.

If HANGUP, OUTOFTIME, return true

Returns
true
false

◆ input_string()

std::string door::Door::input_string ( int  max)

Input a string of requested max length.

This first sends out max number of spaces, and max number of backspaces. This will setup the input area. (If you set a background color of blue, this would allow that to be seen by the user.)

It handles input, backspaces / deleting the characters / enter input and timeout/hangup/out of time.

Parameters
max
Returns
std::string

◆ log()

ofstream & door::Door::log ( void  )

Give ofstream handle for logging.

This appends the current date/time stamp into the logfile, and returns a reference.

Example:

door.log() << "Something bad just happened." << std::endl;

Returns
ofstream&

◆ overflow()

int door::Door::overflow ( int  c)
overrideprivate

Stores a character into the buffer. This does still use the buffer.

Todo:
Replace this also with a direct call to od_disp_emu.
Parameters
cchar
Returns
int

◆ parse_dropfile()

void door::Door::parse_dropfile ( const char *  filepath)
private

Load dropfile into dropfilelines and parse.

Load dropfile and parse door.sys and door32.sys.

Parameters
[in]filepathDropfile path and filename

◆ sleep_key()

signed int door::Door::sleep_key ( int  secs)

Waits secs seconds for a keypress.

returns key, or -1 on timeout (seconds passed). -2 hangup -3 out of time

Parameters
secs
Returns
signed int

◆ sleep_ms_key()

signed int door::Door::sleep_ms_key ( int  msecs)

Waits miliseconds for a keypress.

returns key, or -1 on timeout (seconds passed). -2 hangup -3 out of time

Parameters
msecs
Returns
signed int

◆ xsputn()

std::streamsize door::Door::xsputn ( const char *  s,
std::streamsize  n 
)
overrideprivate

Take given buffer and output it.

If debug_capture is enabled, we save everything to debug_buffer. This is used by the tests.

Parameters
sconst char *
nstd::streamsize
Returns
std::streamsize

Member Data Documentation

◆ cx

int door::Door::cx
Todo:
Current cursor X position.

◆ cy

int door::Door::cy
Todo:
Current cursor Y position.

◆ debug_buffer

std::string door::Door::debug_buffer

Buffer that holds the output for testing.

◆ doorname

std::string door::Door::doorname
private

The name used for logfile

◆ dropfilelines

vector<std::string> door::Door::dropfilelines
private

Contents of the dropfile.

◆ dropfilename

std::string door::Door::dropfilename
private

Name of the dropfile.

◆ handle

std::string door::Door::handle

BBS Dropfile handle

◆ has_dropfile

bool door::Door::has_dropfile
private

Did we read a dropfile?

◆ height

int door::Door::height

Detected screen height.

◆ inactivity

int door::Door::inactivity

Number of seconds before timing out.

When prompting for user input, this is the number of seconds they have to respond before we give up and timeout on them. (Default 120/2 minutes)

◆ location

std::string door::Door::location

BBS Dropfile location

◆ logf

ofstream door::Door::logf
private

Logfile

◆ node

int door::Door::node

BBS Dropfile node number

◆ opt

AnyOption door::Door::opt

Commandline options parser.

◆ previous

ANSIColor door::Door::previous

Previous ANSI-BBS colors and attributes sent. This is used to optimize ANSI Color output.

See also
ANSIColor::output()

◆ seconds_elapsed

int door::Door::seconds_elapsed
private

Used by time_thread to know when a minute has passed.

◆ stop_thread

std::promise<void> door::Door::stop_thread
private

Allow us to stop the time_thread.

◆ sysop

std::string door::Door::sysop

BBS Dropfile sysop name

◆ time_left

atomic<int> door::Door::time_left

time left in minutes

◆ time_thread

std::thread door::Door::time_thread
private

Thread used to update time_left and time_used.

◆ time_used

atomic<int> door::Door::time_used

time used in minutes

◆ tio_default

struct termios door::Door::tio_default
private

Initial terminal defaults.

◆ track

bool door::Door::track
Todo:
Enable tracking cursor position.

◆ username

std::string door::Door::username

BBS Dropfile username

◆ width

int door::Door::width

Detected screen width. Door::detect_unicode_and_screen


The documentation for this class was generated from the following files: