StStME / TelnetServLib

Lightweight C++ Telnet Server for Game loop style programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TelnetServLib is a very light ANSI Telnet Server library for use in apps with 'game
loops': i.e. update, render. It utilises TCP select to enable it to operate in the 
main thread.

There are two classes: TelnetServer, TelnetSession

TelnetServer
============
TelnetServer is responsible for setting up a listening port and accepting 
incoming connections. It also is responsible for keeping TelnetSessions up-to-
date.

Start a TelnetServer with the following code:
    
    // Create your TelnetServer with a shared pointer.
    std::shared_ptr<TelnetServer> ts = std::make_shared < TelnetServer >();

    // Start your TelnetServer on a given port and present an interactive prompt: py>
    ts->initialise(27015, "py> ");

Once your TelnetServer is created you can hook external functions to call when
certain events happen in TelnetSessions.
	
	// Call back after initial telnet client initialised (used for MOTD etc)
    ts->connectedCallback(&MyClass::myConnectedFunction);

    // Call back made after every carriage return from the telnet client
    ts->newLineCallback(&MyClass::myNewLineFunction);

These callback functions should be structured as follows:
    
    void myConnectedFunction(SP_TelnetSession session);
    void myNewLineFunction  (SP_TelnetSession session, std::string line);

SP_TelnetSession is a type definition to a shared pointer to the TelnetSession. With
access to the TelnetSession you can send responses etc.

TelnetSession
=============
TelnetSessions are currently open telnet sessions with clients.

TelnetSessions can be accessed in two ways:
- It is passed to the callback functions
- A list of active sessions can be retrieved from TelnetServer::sessions()

The key functions:
    void sendLine(std::string data);    // Send a line of data to the Telnet Server
    void closeClient();                 // Finish the session

NB: sendline does not require a closing newline.

License
=======
Copyright (c) 2015, Luke Malcolm
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies, 
either expressed or implied, of the FreeBSD Project.

About

Lightweight C++ Telnet Server for Game loop style programs

License:Other


Languages

Language:C++ 95.9%Language:C 2.2%Language:CMake 1.9%