00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _INSOCKET_H
00021 #define _INSOCKET_H
00022
00023 #include <TcpSocket.h>
00024 #include <ISocketHandler.h>
00025 #include <IEventOwner.h>
00026
00027
00028
00029 #define MXP_BEG "\x03"
00030 #define MXP_END "\x04"
00031 #define MXP_AMP "\x05"
00032
00033
00034
00035 #define MXP_BEGc '\x03'
00036 #define MXP_ENDc '\x04'
00037 #define MXP_AMPc '\x05'
00038
00039
00040
00041 #define MXPTAG(arg) MXP_BEG arg MXP_END
00042
00043 #define ESC "\x1B"
00044
00045 #define MXPMODE(arg) ESC "[" #arg "z"
00046
00047
00048
00049 enum
00050 {
00051 eItemNothing,
00052 eItemGet,
00053 eItemDrop,
00054 eItemBid
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;
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