Logo
~Sockets~
~Examples~
~Contact~


ChatSocket Class Reference

#include <ChatSocket.h>

List of all members.


Public Member Functions

 ChatSocket (ISocketHandler &)
 ~ChatSocket ()
void OnAccept ()
void OnLine (const std::string &)
const std::string & GetName ()

Private Member Functions

void SendPrompt ()

Private Attributes

int m_state
std::string m_name

Detailed Description

Definition at line 33 of file ChatSocket.h.


Constructor & Destructor Documentation

ChatSocket::ChatSocket ( ISocketHandler &   ) 

Definition at line 28 of file ChatSocket.cpp.

00029 :TcpSocket(h)
00030 ,m_state(STATE_LOGIN)
00031 ,m_name("")
00032 {
00033         SetLineProtocol();
00034 }

ChatSocket::~ChatSocket (  ) 

Definition at line 37 of file ChatSocket.cpp.

00038 {
00039 }


Member Function Documentation

void ChatSocket::OnAccept (  ) 

Definition at line 42 of file ChatSocket.cpp.

References SendPrompt().

00043 {
00044         Send("Welcome.\n");
00045         SendPrompt();
00046 }

void ChatSocket::OnLine ( const std::string &   ) 

Definition at line 49 of file ChatSocket.cpp.

References m_name, m_state, SendPrompt(), STATE_LOGIN, STATE_PROMPT, and STATE_QUIT.

00050 {
00051         switch (m_state)
00052         {
00053         case STATE_LOGIN:
00054                 if (line.size())
00055                 {
00056                         m_name = line;
00057                         m_state = STATE_PROMPT;
00058                 }
00059                 SendPrompt();
00060                 break;
00061         case STATE_PROMPT:
00062                 if (line.size())
00063                 {
00064                         if (line == "/who")
00065                         {
00066                                 static_cast<DChatHandler&>(Handler()).Who(this);
00067                         }
00068                         else
00069                         if (line == "/quit")
00070                         {
00071                                 m_state = STATE_QUIT;
00072                         }
00073                         else
00074                         {
00075                                 static_cast<DChatHandler&>(Handler()).Talk(m_name,line);
00076                                 Send("You say '" + line + "'\n");
00077                         }
00078                 }
00079                 SendPrompt();
00080                 break;
00081         case STATE_QUIT:
00082                 break;
00083         }
00084 }

const std::string& ChatSocket::GetName (  )  [inline]

Definition at line 42 of file ChatSocket.h.

References m_name.

00042 { return m_name; }

void ChatSocket::SendPrompt (  )  [private]

Definition at line 87 of file ChatSocket.cpp.

References m_state, STATE_LOGIN, STATE_PROMPT, and STATE_QUIT.

Referenced by OnAccept(), and OnLine().

00088 {
00089         switch (m_state)
00090         {
00091         case STATE_LOGIN:
00092                 Send("Enter name: ");
00093                 break;
00094         case STATE_PROMPT:
00095                 Send("> ");
00096                 break;
00097         case STATE_QUIT:
00098                 Send("Goodbye!\n");
00099                 SetCloseAndDelete();
00100                 break;
00101         }
00102 }


Member Data Documentation

int ChatSocket::m_state [private]

Definition at line 46 of file ChatSocket.h.

Referenced by OnLine(), and SendPrompt().

std::string ChatSocket::m_name [private]

Definition at line 47 of file ChatSocket.h.

Referenced by GetName(), and OnLine().


The documentation for this class was generated from the following files:
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