Results 1 to 5 of 5

Thread: Telnet Server

  1. #1
    Join Date
    May 2003
    Posts
    8
    Rep Power
    0

    Default Telnet Server

    Well spent all of last night writing a telnet server and wish to share it with u guys.. well i've not implemented any of the commands but i can tell u it works and the logics is correct.. who's interested in all of the source code can request it and i drop it to u..

    Here's the main DLL though (transmission.dll)

    #include <windows.h>
    #include <server.h>
    #include <stdio.h>

    #define EXPORT __declspec(dllexport)

    typedef struct COMMAND_TAG
    {
    int id;
    char *header;
    }COMMANDS, *LPCOMMANDS;


    void TelnetEnvironment(LPUSEROBJECT, char *, int *);
    void Communication(LPUSEROBJECT, char *);
    int ProcessHeader(char *);
    char *GetHeader(char *);
    void Parse(char *);

    COMMANDS Commands[] =
    {
    {100,"MSGU"},{101,"SEND"},{102 ,"BUZZ"},{103,"PRIV"},
    {104,"LOUT"},{105,"AWAY"},{106 ,"CLIS"},{107,"BACK"},
    {108,"STOP"},{109,"RSET"},{110 ,"KICK"},{111,"VERS"},
    {112,"LIST"},{113,"ONLI"},{114 ,"ADDF"},{115,"DELF"}
    };

    #ifdef __cplusplus
    extern "C" {
    #endif

    EXPORT void Transmission ( LPUSEROBJECT UserObject )
    {
    int *BackSpace = new int(0);
    LPCLIENT ClientStatic = UserObject->Client;
    char *ExecBuffer = new char [ClientStatic->User->packets+1];
    memset(ExecBuffer, 0, ClientStatic->User->packets+1);

    while ( ClientStatic->User->socket->IsConnected() )
    {
    Sleep(0x1);
    while ( !ClientStatic->Queue->empty() )
    TelnetEnvironment( UserObject, ExecBuffer, BackSpace );
    }
    delete BackSpace;
    delete [] ExecBuffer;
    }

    #ifdef __cplusplus
    }
    #endif

    void TelnetEnvironment(LPUSEROBJECT Object, char *ExecBuffer, int *BackSpace)
    {
    LPCLIENT ClientStatic = Object->Client;
    char *Buffer = (char *)ClientStatic->Queue->dequeue();

    switch ( Buffer[0] )
    {
    case 0x0d:/*enter key*/
    {
    char EnterKey[4];
    (*BackSpace) = 0;
    memset(EnterKey, 0, 4);
    wsprintf(EnterKey, "%c%c", 0x0d, 0x0a);
    ClientStatic->User->socket->Send(EnterKey, strlen(EnterKey));
    Communication(Object, ExecBuffer); /*process recieved messages*/
    memset(ExecBuffer, 0, strlen(ExecBuffer));
    }
    break;

    case 0x08:/*backspace*/
    {
    char BSpaceKey[4];
    memset(BSpaceKey, 0, 4);

    if ( (*BackSpace) )
    {
    wsprintf(BSpaceKey, "%c", 0x20);
    ClientStatic->User->socket->Send(Buffer, strlen(Buffer));
    ClientStatic->User->socket->Send(BSpaceKey, strlen(BSpaceKey));
    ClientStatic->User->socket->Send(Buffer, strlen(Buffer));
    (*(&ExecBuffer))[strlen(ExecBuffer) - 1] = 0x0;
    (*BackSpace)--;
    }
    else
    {
    wsprintf(BSpaceKey, "%c", 0x07);
    ClientStatic->User->socket->Send(BSpaceKey, strlen(BSpaceKey));
    }
    }
    break;

    case 0x1b:/*vertical and horizontal arrows*/
    break;

    default:
    ClientStatic->User->socket->Send(Buffer, strlen(Buffer));
    if ( strlen(Buffer) > 1) Communication(Object, Buffer);
    strcat(*(&ExecBuffer), Buffer);
    (*BackSpace)++;
    break;
    }
    }

    int ProcessHeader(char *Packets)
    {
    for(int i = 0; i < (sizeof(Commands) / sizeof(Commands[0])); i++)
    if ( !strcmp(GetHeader(Packets), Commands[i].header) )
    return (Parse(Packets), Commands[i].id);

    return 000;
    }

    char *GetHeader(char *Buffer)
    {
    char sParse[strlen(Buffer)];
    char Header[strlen(Buffer)+1], *HeaderPtr;
    memset(Header, 0, strlen(Buffer)+1);
    sscanf(Buffer, "%s %s", &Header, &sParse);
    return (HeaderPtr = Header);
    }

    void Parse(char *Buffer)
    {
    int dPos, pPos = 0;
    for (dPos = 0; dPos <= strlen(Buffer); dPos++) if (Buffer[dPos] == 0x20 ) break;
    dPos ++; char ParseBuffer[(strlen(Buffer)+1)-dPos];
    memset(ParseBuffer, 0, (strlen(Buffer)+1)-dPos);
    for (int i = dPos; i < strlen(Buffer); i++ )
    { ParseBuffer[pPos] = Buffer[i]; pPos++; }
    strcpy(*(&Buffer), ParseBuffer);
    }

    void Communication(LPUSEROBJECT Object, char *Buffer)
    {
    LINKLIST *ListNode = Object->ListObject;
    LPCLIENT ClientStatic = Object->Client;

    switch ( ProcessHeader( Buffer ) /*will do packet parsing*/)
    {
    case 100:
    break;

    case 101:
    break;

    case 102:
    break;

    case 103:
    break;

    case 104:
    break;

    case 105:
    break;

    case 106:
    break;

    case 107:
    break;

    case 108:
    break;

    case 109:
    break;

    case 110:
    break;

    case 111:
    break;

    case 112:
    break;

    case 113:
    break;

    case 114:
    break;

    case 115:
    break;

    default:
    break;
    }
    }

  2. #2
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default Re:Telnet Server

    don't post alot a text like that. : next time just attach a text file when your posting. it's neater and takes less time to download. I haven't been doing any c++ coding recently pure web stuff.

  3. #3
    Join Date
    Mar 2003
    Posts
    1,700
    Rep Power
    0

    Default Re:Telnet Server

    contageous, try using code tags. It makes the text easier to identify.

    For example, your code could look like this:

    Code:
    #include <windows.h>
    #include <server.h>
    #include <stdio.h>
    
    #define EXPORT __declspec(dllexport)
    
    typedef struct COMMAND_TAG
    {
      int id;
      char *header;
    }COMMANDS, *LPCOMMANDS;
    
    
    void TelnetEnvironment(LPUSEROBJECT, char *, int *);
    void Communication(LPUSEROBJECT, char *);
    int ProcessHeader(char *);
    char *GetHeader(char *);
    void Parse(char *);
    
    COMMANDS Commands[] = 
    {
      {100,"MSGU"},{101,"SEND"},{102,"BUZZ"},{103,"PRIV"},
      {104,"LOUT"},{105,"AWAY"},{106,"CLIS"},{107,"BACK"},
      {108,"STOP"},{109,"RSET"},{110,"KICK"},{111,"VERS"},
      {112,"LIST"},{113,"ONLI"},{114,"ADDF"},{115,"DELF"}
    };
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    .
    .
    .
    .
    .
    //and so on
    The code tags can do the trick. Ofcourse, if it's lengthy, file attachments can't be beat.

  4. #4
    Join Date
    May 2003
    Posts
    896
    Rep Power
    0

    Default Re:Telnet Server

    Nice Telnet Server contageous...this is the kinda stuff I like to see. Its good when we can post our work and have comments and tips given to help us learn.

  5. #5
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default Re:Telnet Server

    Hey contagious, your email is hidden, so I guess I have to ask you for a copy here. Yeah I want a copy, cus i've never really tried creating dll files before, and I want to give it a shot. By the way my email is hidden also. Its alex_bigballer.at.yahoo.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •