Chat bot integration now fully functional.

This commit is contained in:
lotodore
2009-08-17 09:45:06 +00:00
parent f7885f9116
commit 836ec60e6d
18 changed files with 180 additions and 37 deletions
+5 -1
View File
@@ -552,7 +552,8 @@ ChatMessage ::= [APPLICATION 130] SEQUENCE {
chatType CHOICE {
chatTypeLobby [0] ChatTypeLobby,
chatTypeGame [1] ChatTypeGame,
chatTypeBroadcast [2] ChatTypeBroadcast
chatTypeBot [2] ChatTypeBot,
chatTypeBroadcast [3] ChatTypeBroadcast
},
chatText UTF8String (SIZE(1..128))
}
@@ -569,6 +570,9 @@ ChatTypeGame ::= SEQUENCE {
ChatTypeBroadcast ::= SEQUENCE {
}
ChatTypeBot ::= SEQUENCE {
}
DialogMessage ::= [APPLICATION 131] SEQUENCE {
notificationText UTF8String (SIZE(1..128))
}
+2
View File
@@ -64,6 +64,7 @@ HEADERS += \
src/engine/berointerface.h \
src/gui/guiinterface.h \
src/net/chatcleanermanager.h \
src/net/chatcleanercallback.h \
src/net/clientcallback.h \
src/net/clientcontext.h \
src/net/clientexception.h \
@@ -166,6 +167,7 @@ SOURCES += \
src/engine/network_engine/clientplayer.cpp \
src/engine/network_engine/clientbero.cpp \
src/net/common/chatcleanermanager.cpp \
src/net/common/chatcleanercallback.cpp \
src/net/common/clientcallback.cpp \
src/net/common/clientcontext.cpp \
src/net/common/clientstate.cpp \
+3 -1
View File
@@ -56,6 +56,7 @@ HEADERS += src/third_party/asn1/AllInShowCardsMessage.h \
src/third_party/asn1/ChatMessage.h \
src/third_party/asn1/ChatTypeGame.h \
src/third_party/asn1/ChatTypeLobby.h \
src/third_party/asn1/ChatTypeBot.h \
src/third_party/asn1/ChatTypeBroadcast.h \
src/third_party/asn1/ChatRequestMessage.h \
src/third_party/asn1/ChatRequestTypeLobby.h \
@@ -247,8 +248,9 @@ SOURCES += src/third_party/asn1/ChatCleanerMessage.c \
src/third_party/asn1/ChatRequestTypeLobby.c \
src/third_party/asn1/ChatRequestTypeGame.c \
src/third_party/asn1/ChatMessage.c \
src/third_party/asn1/ChatTypeLobby.c \
src/third_party/asn1/ChatTypeGame.c \
src/third_party/asn1/ChatTypeLobby.c \
src/third_party/asn1/ChatTypeBot.c \
src/third_party/asn1/ChatTypeBroadcast.c \
src/third_party/asn1/Card.c \
src/third_party/asn1/BOOLEAN.c \
+1 -1
View File
@@ -224,7 +224,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
configList.push_back(ConfigInfo("AdminIRCServerNick", CONFIG_TYPE_INT, "PokerTH"));
configList.push_back(ConfigInfo("UseChatCleaner", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("ChatCleanerHostAddress", CONFIG_TYPE_STRING, "localhost"));
configList.push_back(ConfigInfo("ChatCleanerPort", CONFIG_TYPE_INT, "4237"));
configList.push_back(ConfigInfo("ChatCleanerPort", CONFIG_TYPE_INT, "4327"));
configList.push_back(ConfigInfo("ChatCleanerClientAuth", CONFIG_TYPE_STRING, ""));
configList.push_back(ConfigInfo("ChatCleanerServerAuth", CONFIG_TYPE_STRING, ""));
configList.push_back(ConfigInfo("ChatCleanerUseIpv6", CONFIG_TYPE_INT, "0"));
+3 -1
View File
@@ -25,13 +25,14 @@
#include <boost/enable_shared_from_this.hpp>
#include <string>
#include <net/internalchatcleanerpacket.h>
#include <net/chatcleanercallback.h>
class EncodedPacket;
class ChatCleanerManager : public boost::enable_shared_from_this<ChatCleanerManager>
{
public:
ChatCleanerManager(boost::shared_ptr<boost::asio::io_service> ioService);
ChatCleanerManager(ChatCleanerCallback &cb, boost::shared_ptr<boost::asio::io_service> ioService);
virtual ~ChatCleanerManager();
void Init(const std::string &serverAddr, int port, bool ipv6,
@@ -51,6 +52,7 @@ protected:
private:
ChatCleanerCallback &m_callback;
boost::shared_ptr<boost::asio::io_service> m_ioService;
boost::shared_ptr<boost::asio::ip::tcp::resolver> m_resolver;
boost::shared_ptr<boost::asio::ip::tcp::socket> m_socket;
+26 -16
View File
@@ -29,8 +29,8 @@ using namespace std;
using boost::asio::ip::tcp;
ChatCleanerManager::ChatCleanerManager(boost::shared_ptr<boost::asio::io_service> ioService)
: m_ioService(ioService), m_connected(false), m_curRequestId(0), m_recvBufUsed(0)
ChatCleanerManager::ChatCleanerManager(ChatCleanerCallback &cb, boost::shared_ptr<boost::asio::io_service> ioService)
: m_callback(cb), m_ioService(ioService), m_connected(false), m_curRequestId(0), m_recvBufUsed(0)
{
m_resolver.reset(
new boost::asio::ip::tcp::resolver(*m_ioService));
@@ -125,21 +125,22 @@ ChatCleanerManager::HandleConnect(const boost::system::error_code& ec,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator())
{
// Try next resolve entry.
m_socket->close();
boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
m_socket->async_connect(
endpoint,
boost::bind(&ChatCleanerManager::HandleConnect,
shared_from_this(),
boost::asio::placeholders::error,
++endpoint_iterator));
}
else if (ec != boost::asio::error::operation_aborted)
{
LOG_ERROR("Could not connect to chat cleaner server.");
if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator())
{
// Try next resolve entry.
m_socket->close();
boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
m_socket->async_connect(
endpoint,
boost::bind(&ChatCleanerManager::HandleConnect,
shared_from_this(),
boost::asio::placeholders::error,
++endpoint_iterator));
}
else
LOG_ERROR("Could not connect to chat cleaner server.");
}
}
@@ -179,7 +180,10 @@ ChatCleanerManager::HandleRead(const boost::system::error_code &ec, size_t bytes
else
m_recvBufUsed = 0;
error = HandleMessage(recvMsg);
if (asn_check_constraints(&asn_DEF_ChatCleanerMessage, recvMsg.GetMsg(), NULL, NULL) == 0)
error = HandleMessage(recvMsg);
else
LOG_ERROR("Received invalid chat cleaner packet.");
}
} while (!error && retVal.code == RC_OK);
@@ -226,6 +230,12 @@ ChatCleanerManager::HandleMessage(InternalChatCleanerPacket &msg)
if (!m_connected)
LOG_ERROR("Chat cleaner handshake failed.");
}
else if (msg.GetMsg()->present == ChatCleanerMessage_PR_cleanerChatReplyMessage)
{
CleanerChatReplyMessage_t *netReply = &msg.GetMsg()->choice.cleanerChatReplyMessage;
m_callback.SignalChatBotMessage(string((const char *)netReply->cleanerText->buf, netReply->cleanerText->size));
error = false;
}
return error;
}
+4
View File
@@ -813,6 +813,10 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
client->GetCallback().SignalNetClientGameChatMsg("(global notice)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
client->GetCallback().SignalNetClientLobbyChatMsg("(global notice)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
}
else if (netMessage->chatType.present == chatType_PR_chatTypeBot)
{
client->GetCallback().SignalNetClientLobbyChatMsg("(chat bot)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
}
else if (netMessage->chatType.present == chatType_PR_chatTypeGame)
{
unsigned playerId = netMessage->chatType.choice.chatTypeGame.playerId;
+23 -2
View File
@@ -68,7 +68,7 @@ using namespace std;
using boost::asio::ip::tcp;
class ServerSenderCallback : public SenderCallback, public SessionDataCallback
class ServerSenderCallback : public SenderCallback, public SessionDataCallback, public ChatCleanerCallback
{
public:
ServerSenderCallback(ServerLobbyThread &server) : m_server(server) {}
@@ -84,6 +84,10 @@ public:
{
m_server.GetSender().SignalSessionTerminated(session);
}
virtual void SignalChatBotMessage(const string &msg)
{
m_server.SendChatBotMsg(msg);
}
private:
ServerLobbyThread &m_server;
@@ -103,7 +107,7 @@ ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig
m_sender.reset(new SenderHelper(*m_senderCallback, m_ioService));
m_receiver.reset(new ReceiverHelper);
m_banManager.reset(new ServerBanManager(m_ioService));
m_chatCleanerManager.reset(new ChatCleanerManager(m_ioService));
m_chatCleanerManager.reset(new ChatCleanerManager(*m_senderCallback, m_ioService));
}
ServerLobbyThread::~ServerLobbyThread()
@@ -445,9 +449,26 @@ ServerLobbyThread::SendGlobalMsgBox(const string &message)
&netDialog->notificationText,
message.c_str(),
message.length());
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
}
void
ServerLobbyThread::SendChatBotMsg(const std::string &message)
{
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
netChat->chatType.present = chatType_PR_chatTypeBot;
OCTET_STRING_fromBuf(
&netChat->chatText,
message.c_str(),
message.length());
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
}
void
ServerLobbyThread::AddComputerPlayer(boost::shared_ptr<PlayerData> player)
{
+1
View File
@@ -80,6 +80,7 @@ public:
void SendGlobalChat(const std::string &message);
void SendGlobalMsgBox(const std::string &message);
void SendChatBotMsg(const std::string &message);
void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
void RemoveComputerPlayer(boost::shared_ptr<PlayerData> player);
+19 -8
View File
@@ -59,9 +59,18 @@ static asn_TYPE_member_t asn_MBR_chatType_2[] = {
0,
"chatTypeGame"
},
{ ATF_NOFLAGS, 0, offsetof(struct chatType, choice.chatTypeBroadcast),
{ ATF_NOFLAGS, 0, offsetof(struct chatType, choice.chatTypeBot),
(ASN_TAG_CLASS_CONTEXT | (2 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_ChatTypeBot,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"chatTypeBot"
},
{ ATF_NOFLAGS, 0, offsetof(struct chatType, choice.chatTypeBroadcast),
(ASN_TAG_CLASS_CONTEXT | (3 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_ChatTypeBroadcast,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
@@ -72,7 +81,8 @@ static asn_TYPE_member_t asn_MBR_chatType_2[] = {
static asn_TYPE_tag2member_t asn_MAP_chatType_tag2el_2[] = {
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* chatTypeLobby at 553 */
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* chatTypeGame at 554 */
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* chatTypeBroadcast at 556 */
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 }, /* chatTypeBot at 555 */
{ (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 3, 0, 0 } /* chatTypeBroadcast at 557 */
};
static asn_CHOICE_specifics_t asn_SPC_chatType_specs_2 = {
sizeof(struct chatType),
@@ -80,9 +90,9 @@ static asn_CHOICE_specifics_t asn_SPC_chatType_specs_2 = {
offsetof(struct chatType, present),
sizeof(((struct chatType *)0)->present),
asn_MAP_chatType_tag2el_2,
3, /* Count of tags in the map */
4, /* Count of tags in the map */
0,
3 /* Extensions start */
4 /* Extensions start */
};
static /* Use -fall-defs-global to expose */
asn_TYPE_descriptor_t asn_DEF_chatType_2 = {
@@ -103,7 +113,7 @@ asn_TYPE_descriptor_t asn_DEF_chatType_2 = {
0, /* No tags (count) */
0, /* No PER visible constraints */
asn_MBR_chatType_2,
3, /* Elements count */
4, /* Elements count */
&asn_SPC_chatType_specs_2 /* Additional specs */
};
@@ -132,16 +142,17 @@ static ber_tlv_tag_t asn_DEF_ChatMessage_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn_TYPE_tag2member_t asn_MAP_ChatMessage_tag2el_1[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (12 << 2)), 1, 0, 0 }, /* chatText at 557 */
{ (ASN_TAG_CLASS_UNIVERSAL | (12 << 2)), 1, 0, 0 }, /* chatText at 558 */
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* chatTypeLobby at 553 */
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 0, 0, 0 }, /* chatTypeGame at 554 */
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 0, 0, 0 } /* chatTypeBroadcast at 556 */
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 0, 0, 0 }, /* chatTypeBot at 555 */
{ (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 0, 0, 0 } /* chatTypeBroadcast at 557 */
};
static asn_SEQUENCE_specifics_t asn_SPC_ChatMessage_specs_1 = {
sizeof(struct ChatMessage),
offsetof(struct ChatMessage, _asn_ctx),
asn_MAP_ChatMessage_tag2el_1,
4, /* Count of tags in the map */
5, /* Count of tags in the map */
0, 0, 0, /* Optional elements (not needed) */
1, /* Start extensions */
3 /* Stop extensions */
+3
View File
@@ -14,6 +14,7 @@
#include <UTF8String.h>
#include "ChatTypeLobby.h"
#include "ChatTypeGame.h"
#include "ChatTypeBot.h"
#include "ChatTypeBroadcast.h"
#include <constr_CHOICE.h>
#include <constr_SEQUENCE.h>
@@ -27,6 +28,7 @@ typedef enum chatType_PR {
chatType_PR_NOTHING, /* No components present */
chatType_PR_chatTypeLobby,
chatType_PR_chatTypeGame,
chatType_PR_chatTypeBot,
chatType_PR_chatTypeBroadcast,
/* Extensions may appear below */
@@ -39,6 +41,7 @@ typedef struct ChatMessage {
union ChatMessage__chatType_u {
ChatTypeLobby_t chatTypeLobby;
ChatTypeGame_t chatTypeGame;
ChatTypeBot_t chatTypeBot;
ChatTypeBroadcast_t chatTypeBroadcast;
/*
* This type is extensible,
+45
View File
@@ -0,0 +1,45 @@
/*
* Generated by asn1c-0.9.22 (http://lionet.info/asn1c)
* From ASN.1 module "POKERTH-PROTOCOL"
* found in "../../../docs/pokerth.asn1"
*/
#include <asn_internal.h>
#include "ChatTypeBot.h"
static ber_tlv_tag_t asn_DEF_ChatTypeBot_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn_SEQUENCE_specifics_t asn_SPC_ChatTypeBot_specs_1 = {
sizeof(struct ChatTypeBot),
offsetof(struct ChatTypeBot, _asn_ctx),
0, /* No top level tags */
0, /* No tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1 /* Stop extensions */
};
asn_TYPE_descriptor_t asn_DEF_ChatTypeBot = {
"ChatTypeBot",
"ChatTypeBot",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint,
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
SEQUENCE_decode_xer,
SEQUENCE_encode_xer,
0, 0, /* No PER support, use "-gen-PER" to enable */
0, /* Use generic outmost tag fetcher */
asn_DEF_ChatTypeBot_tags_1,
sizeof(asn_DEF_ChatTypeBot_tags_1)
/sizeof(asn_DEF_ChatTypeBot_tags_1[0]), /* 1 */
asn_DEF_ChatTypeBot_tags_1, /* Same as above */
sizeof(asn_DEF_ChatTypeBot_tags_1)
/sizeof(asn_DEF_ChatTypeBot_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
0, 0, /* No members */
&asn_SPC_ChatTypeBot_specs_1 /* Additional specs */
};
+38
View File
@@ -0,0 +1,38 @@
/*
* Generated by asn1c-0.9.22 (http://lionet.info/asn1c)
* From ASN.1 module "POKERTH-PROTOCOL"
* found in "../../../docs/pokerth.asn1"
*/
#ifndef _ChatTypeBot_H_
#define _ChatTypeBot_H_
#include <asn_application.h>
/* Including external dependencies */
#include <constr_SEQUENCE.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ChatTypeBot */
typedef struct ChatTypeBot {
/*
* This type is extensible,
* possible extensions are below.
*/
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} ChatTypeBot_t;
/* Implementation */
extern asn_TYPE_descriptor_t asn_DEF_ChatTypeBot;
#ifdef __cplusplus
}
#endif
#endif /* _ChatTypeBot_H_ */
+2 -2
View File
@@ -32,8 +32,8 @@ static ber_tlv_tag_t asn_DEF_ChatTypeGame_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn_TYPE_tag2member_t asn_MAP_ChatTypeGame_tag2el_1[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 1 }, /* gameId at 565 */
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 1, -1, 0 } /* playerId at 567 */
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 1 }, /* gameId at 566 */
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 1, -1, 0 } /* playerId at 568 */
};
static asn_SEQUENCE_specifics_t asn_SPC_ChatTypeGame_specs_1 = {
sizeof(struct ChatTypeGame),
+1 -1
View File
@@ -23,7 +23,7 @@ static ber_tlv_tag_t asn_DEF_ChatTypeLobby_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn_TYPE_tag2member_t asn_MAP_ChatTypeLobby_tag2el_1[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 } /* playerId at 562 */
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 } /* playerId at 563 */
};
static asn_SEQUENCE_specifics_t asn_SPC_ChatTypeLobby_specs_1 = {
sizeof(struct ChatTypeLobby),
+1 -1
View File
@@ -56,7 +56,7 @@ static ber_tlv_tag_t asn_DEF_DialogMessage_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn_TYPE_tag2member_t asn_MAP_DialogMessage_tag2el_1[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (12 << 2)), 0, 0, 0 } /* notificationText at 573 */
{ (ASN_TAG_CLASS_UNIVERSAL | (12 << 2)), 0, 0, 0 } /* notificationText at 577 */
};
static asn_SEQUENCE_specifics_t asn_SPC_DialogMessage_specs_1 = {
sizeof(struct DialogMessage),
+1 -1
View File
@@ -165,7 +165,7 @@ static ber_tlv_tag_t asn_DEF_ErrorMessage_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn_TYPE_tag2member_t asn_MAP_ErrorMessage_tag2el_1[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (10 << 2)), 0, 0, 0 } /* errorReason at 589 */
{ (ASN_TAG_CLASS_UNIVERSAL | (10 << 2)), 0, 0, 0 } /* errorReason at 593 */
};
static asn_SEQUENCE_specifics_t asn_SPC_ErrorMessage_specs_1 = {
sizeof(struct ErrorMessage),
+2 -2
View File
@@ -150,8 +150,8 @@ static ber_tlv_tag_t asn_DEF_TimeoutWarningMessage_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn_TYPE_tag2member_t asn_MAP_TimeoutWarningMessage_tag2el_1[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 1, 0, 0 }, /* remainingSeconds at 582 */
{ (ASN_TAG_CLASS_UNIVERSAL | (10 << 2)), 0, 0, 0 } /* timeoutReason at 578 */
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 1, 0, 0 }, /* remainingSeconds at 586 */
{ (ASN_TAG_CLASS_UNIVERSAL | (10 << 2)), 0, 0, 0 } /* timeoutReason at 582 */
};
static asn_SEQUENCE_specifics_t asn_SPC_TimeoutWarningMessage_specs_1 = {
sizeof(struct TimeoutWarningMessage),