From: Keith F. <ven...@us...> - 2002-01-19 07:13:05
|
Update of /cvsroot/planeshift/planeshift/src/client In directory usw-pr-cvs1:/tmp/cvs-serv19435 Added Files: chatclient.h chatclient.cpp Log Message: Added support for chatting in window. --- NEW FILE: chatclient.h --- /* psChatClient.h * (c) Keith Fulton 2002 <ke...@pa...> * * This implements a subscriber object which displays incoming chat packets */ #ifndef __psChatClient_H__ #define __psChatClient_H__ #include "net/messages.h" // Chat Message definitions #include "psclientmsghandler.h" // Subscriber definition #include "gui/psgwchat.h" // psChatWindow class, responsible for display #include "interface/subscriber.h" // Subscriber class struct iDialogManager; class psChatClient : public iSubscriber { protected: psClientMsgHandler *msgqueue; iDialogManager *chat; public: SCF_DECLARE_IBASE; psChatClient(psClientMsgHandler *mh); virtual ~psChatClient(); void RegisterWindow(iDialogManager *dialogmanager) { chat = dialogmanager; }; char *SendChat(char *buff); virtual void Interpret(const MsgEntry *pMsg); }; #endif --- NEW FILE: chatclient.cpp --- /* psChatClient.cpp * (c) 2002 Keith Fulton <ke...@pa...> */ #include "config.h" #include "chatclient.h" #include "util/pserror.h" #include "iclient/idmngr.h" SCF_IMPLEMENT_IBASE( psChatClient ) SCF_IMPLEMENTS_INTERFACE( iSubscriber ) SCF_IMPLEMENT_IBASE_END psChatClient::psChatClient(psClientMsgHandler *mh) { msgqueue = mh; chat = NULL; msgqueue->Subscribe(MSGTYPECHAT,this); } psChatClient::~psChatClient() { } void psChatClient::Interpret(const MsgEntry *pMsg ) { psChatMessage msg(pMsg); char *pType; char buff[2000]; strcpy(buff,""); msg.GetTypeText(pType); switch (msg.iChatType) { case CHAT_GROUP: case CHAT_SHOUT: case CHAT_GUILD: case CHAT_AUCTION: { sprintf(buff,"%s from %s: %s\n",pType,(const char *)msg.sPerson,(const char *)msg.sText); break; } case CHAT_SAY: { sprintf(buff,"%s says: %s\n",(const char *)msg.sPerson,(const char *)msg.sText); break; } case CHAT_ME: { sprintf(buff,"%s %s\n",(const char *)msg.sPerson,(const char *)msg.sText); break; } case CHAT_TELL: { sprintf(buff,"%s tells you: %s\n",(const char *)msg.sPerson,(const char *)msg.sText); break; } default: { sprintf(buff,"Unknown Chat Type: %d\n",msg.iChatType); break; } } if (buff[0] && chat) { chat->AddChatLine(buff); } } char *psChatClient::SendChat(char *buff) { char *pPerson,*pText; if (buff[0] != '/') { return "Sorry, but chat messages must start with a slash (/) character."; } if (!strncmp(buff+1,"say ",4)) { pPerson = buff + 1; pText = buff + 5; *(pText-1) = 0; // separate two fields by NULL } else if (!strncmp(buff+1,"group ",6) || !strncmp(buff+1,"guild ",6) || !strncmp(buff+1,"shout ",6)) { pPerson = buff + 1; pText = buff + 7; *(pText-1) = 0; // separate two fields by NULL } else if (!strncmp(buff+1,"tell ",5)) { pPerson = buff + 6; pText = strchr(pPerson,' ') + 1; // Next word is ptr to sentence *(pText-1) = 0; // separate two fields by NULL } else if (!strncmp(buff+1,"auction ",8)) { pPerson = buff + 1; pText = buff + 9; *(pText-1) = 0; } else if (!strncmp(buff+1,"me ",3)) { pPerson = buff + 1; pText = buff + 4; *(pText-1) = 0; } else { return "Sorry, but /say, /me, /shout, /group, /guild, /auction and /tell <person> are the only allowable commands."; } psChatMessage chat(pPerson,pText); msgqueue->SendMsg(chat.msg); chat.Detach(); // don't free in dtor printf("Sent the message <%s> with command <%s>.\n",pText,pPerson); return NULL; // Null means no message to print } |