Logo
~Sockets~
~Examples~
~Contact~

InSocket.h

Go to the documentation of this file.
00001 // InSocket.h
00002 // released 2006-09-25
00003 /*
00004 Copyright (C) 2006  Anders Hedstrom (grymse@alhem.net)
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 */
00020 #ifndef _INSOCKET_H
00021 #define _INSOCKET_H
00022 
00023 #include <TcpSocket.h>
00024 #include <ISocketHandler.h>
00025 #include <IEventOwner.h>
00026 
00027 /* strings */
00028 
00029 #define MXP_BEG "\x03"    /* becomes < */
00030 #define MXP_END "\x04"    /* becomes > */
00031 #define MXP_AMP "\x05"    /* becomes & */
00032 
00033 /* characters */
00034 
00035 #define MXP_BEGc '\x03'    /* becomes < */
00036 #define MXP_ENDc '\x04'    /* becomes > */
00037 #define MXP_AMPc '\x05'    /* becomes & */
00038 
00039 /* constructs an MXP tag with < and > around it */
00040 
00041 #define MXPTAG(arg) MXP_BEG arg MXP_END
00042 
00043 #define ESC "\x1B"  /* esc character */
00044 
00045 #define MXPMODE(arg) ESC "[" #arg "z"
00046 
00047 /* flags for show_list_to_char */
00048 
00049 enum 
00050 {
00051         eItemNothing,   /* item is not readily accessible */
00052         eItemGet,     /* item on ground */
00053         eItemDrop,    /* item in inventory */
00054         eItemBid     /* auction item */
00055 };
00056 
00057 
00058 class Command;
00059 class Player;
00060 class FutureHandler;
00061 class Database;
00062 struct EVENT;
00063 
00066 class InSocket : public TcpSocket,public IEventOwner
00067 {
00068 public:
00069         InSocket(ISocketHandler&);
00070         ~InSocket();
00071 
00072         void OnDelete();
00073         void OnAccept();
00074         void OnLine(const std::string& );
00075         void ReadLine();
00076 
00077         void Send(const std::string&);
00078         void Sendf(char *format, ...);
00079         void SendPrompt();
00080 
00081         void SetPrompt(const std::string& = "",bool colorize = true);
00082         void SetPrompt(Command *,int state,const std::string& ,bool colorize = true);
00083         void SetCommandData(const std::string& x) { m_command_data = x; }
00084         const std::string& GetCommandData() { return m_command_data; }
00085         void SetCommandData2(const std::string& x) { m_command_data2 = x; }
00086         const std::string& GetCommandData2() { return m_command_data2; }
00087 
00088         bool UseMxp() { return m_b_use_mxp; }
00089         Database& GetDatabase();
00090 
00091         void SetAccountName(const std::string& x) { m_account_name = x; }
00092         const std::string& GetAccountName() { return m_account_name; }
00093 
00094         void OnEvent(int id);
00095         int AddEvent(long sec,long usec);
00096 
00097         int GetMoveEvent() { return m_move_event; }
00098         void SetMoveEvent(long sec,long usec);
00099         void BufferMove(const std::string& );
00100         void CancelMoves();
00101 
00102         void GlobalEvent(const std::string&);
00103         void Count(const std::string& );
00104 
00105 private:
00106         void send_mxp_defines();
00107         void write_to_buffer(const char *);
00108         void write_to_buffer(const unsigned char *);
00109         std::string m_prompt;
00110         Command *m_active_command;
00111         int m_command_state;
00112         std::string m_command_data; // 1
00113         std::string m_command_data2;
00114         bool m_colorize_prompt;
00115         bool m_b_use_mxp;
00116         std::string m_account_name;
00117         int m_move_event;
00118         std::list<std::string> m_move_buffer;
00119         std::string m_line;
00120 };
00121 
00122 
00123 
00124 
00125 #endif // _INSOCKET_H
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4