From 863e8e79446f18ffeddaf5593e205a850e2020f5 Mon Sep 17 00:00:00 2001 From: Mini Date: Sun, 14 Jan 2007 00:53:17 +0000 Subject: [PATCH] Added enablechatai config option and fixed various bugs in Chat AI (more to come lol xD) --- src/Client/Chat.cpp | 26 +++----------------------- src/Client/PseuWoW.cpp | 1 + src/Client/PseuWoW.h | 1 + src/Client/World/WorldSession.cpp | 7 ++++++- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/Client/Chat.cpp b/src/Client/Chat.cpp index 7bbe966..14e502e 100644 --- a/src/Client/Chat.cpp +++ b/src/Client/Chat.cpp @@ -7,23 +7,6 @@ #include "Chat.h" -/* -int chatCallBackQuestionTypes(void *arg, int nColumns, char **sValues, char **sNames) -{ - if (nColumns != 2) - { - log("Got wrong number of columns for table `talk_types`, columns was: ", nColumns, ", expected 2 columns."); - return -1; - } - - ChatTypes[nChatTypes].type = sValues[0]; - ChatTypes[nChatTypes].remove = atoi(sValues[1]); - nChatTypes++; - - return 0; -}*/ - - // TODO: Rewrite class (Rewritten from old php code - i didn't knew anything else but very simple select, insert, delete statements when // the code was originaly written. :P @@ -52,12 +35,13 @@ Chat::Chat(std::string sentence) // 1. Find the type of sentence // 2. Answer the sentence the right way + sentence = stringToLower(sentence); result = ""; Database chatDB("db/chat"); Query query(chatDB); - query.get_result("select type, remove from talk_types"); + query.get_result("select type, remove from talk_types order by type DESC"); std::string type, part, resultSentence; int remove; @@ -70,13 +54,9 @@ Chat::Chat(std::string sentence) Query query2(chatDB); query2.get_result("select part from talk_types_parts where type='" + type + "'"); - printf("Type: %s\n", type.c_str()); - while (query2.fetch_row()) { - part = query2.getstr(); - - printf("Type: %s, Sentence: %s, Part: %s\n", type.c_str(), sentence.c_str(), part.c_str()); + part = stringToLower(query2.getstr()); if (sentence.find(part) != std::string::npos) { diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index 43319d4..cb0c6aa 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -260,6 +260,7 @@ void PseuInstanceConf::ApplyFromVarSet(VarSet &v) showopcodes=atoi(v.Get("SHOWOPCODES").c_str()); enablecli=(bool)atoi(v.Get("ENABLECLI").c_str()); allowgamecmd=(bool)atoi(v.Get("ALLOWGAMECMD").c_str()); + enablechatai=(bool)atoi(v.Get("ENABLECHATAI").c_str()); // clientversion is a bit more complicated to add { diff --git a/src/Client/PseuWoW.h b/src/Client/PseuWoW.h index d5f999c..94766fd 100644 --- a/src/Client/PseuWoW.h +++ b/src/Client/PseuWoW.h @@ -42,6 +42,7 @@ class PseuInstanceConf uint8 showopcodes; bool allowgamecmd; bool enablecli; + bool enablechatai; }; diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 57d73f8..ba1df67 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -394,7 +394,12 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket) // some fun code :P if(type==CHAT_MSG_SAY && target_guid!=_myGUID && !isCmd) { - Chat *chat = new Chat(msg); + if (GetInstance()->GetConf()->enablechatai) + { + Chat *chat = new Chat(msg); + SendChatMessage(CHAT_MSG_SAY, lang, chat->GetResult(), ""); + delete chat; + } SendChatMessage(CHAT_MSG_SAY, lang, chat->GetResult(), "");