some chat functionality

This commit is contained in:
Eduardo Bart
2012-01-13 23:37:15 -02:00
parent aae784468b
commit 61aa710d1c
27 changed files with 345 additions and 146 deletions

View File

@@ -39,7 +39,7 @@ void Module::discover(const OTMLNodePtr& moduleNode)
m_website = moduleNode->valueAt("website", none);
m_version = moduleNode->valueAt("version", none);
m_autoLoad = moduleNode->valueAt<bool>("autoLoad", false);
m_autoLoadPriority = moduleNode->valueAt<int>("autoLoadPriority", 100);
m_autoLoadAntecedence = moduleNode->valueAt<int>("autoLoadAntecedence", 100);
if(OTMLNodePtr node = moduleNode->get("dependencies")) {
for(const OTMLNodePtr& tmp : node->children())

View File

@@ -44,12 +44,12 @@ public:
std::string getWebsite() { return m_website; }
std::string getVersion() { return m_version; }
bool isAutoLoad() { return m_autoLoad; }
int getAutoLoadPriority() { return m_autoLoadPriority; }
int getAutoLoadAntecedence() { return m_autoLoadAntecedence; }
private:
Boolean<false> m_loaded;
Boolean<false> m_autoLoad;
int m_autoLoadPriority;
int m_autoLoadAntecedence;
std::string m_name;
std::string m_description;
std::string m_author;

View File

@@ -37,17 +37,17 @@ void ModuleManager::discoverModules()
if(boost::ends_with(moduleFile, ".otmod")) {
ModulePtr module = discoverModule("/" + moduleDir + "/" + moduleFile);
if(module && module->isAutoLoad())
m_autoLoadModules.insert(make_pair(module->getAutoLoadPriority(), module));
m_autoLoadModules.insert(make_pair(module->getAutoLoadAntecedence(), module));
}
}
}
}
void ModuleManager::autoLoadModules(int maxPriority)
void ModuleManager::autoLoadModules(int maxAntecedence)
{
for(auto& pair : m_autoLoadModules) {
int priority = pair.first;
if(priority > maxPriority)
if(priority > maxAntecedence)
break;
ModulePtr module = pair.second;
if(!module->isLoaded() && !module->load())

View File

@@ -30,7 +30,7 @@ class ModuleManager
public:
void discoverModulesPath();
void discoverModules();
void autoLoadModules(int maxPriority);
void autoLoadModules(int maxAntecedence);
ModulePtr discoverModule(const std::string& moduleFile);
void ensureModuleLoaded(const std::string& moduleName);
void unloadModules();

View File

@@ -340,23 +340,23 @@ int Game::getThingStackpos(const ThingPtr& thing)
void Game::talk(const std::string& message)
{
talkChannel(1, 0, message);
talkChannel("say", 0, message);
}
void Game::talkChannel(int channelType, int channelId, const std::string& message)
void Game::talkChannel(const std::string& speakTypeDesc, int channelId, const std::string& message)
{
if(!m_online || !checkBotProtection())
return;
m_protocolGame->sendTalk(channelType, channelId, "", message);
m_protocolGame->sendTalk(speakTypeDesc, channelId, "", message);
}
void Game::talkPrivate(int channelType, const std::string& receiver, const std::string& message)
void Game::talkPrivate(const std::string& speakTypeDesc, const std::string& receiver, const std::string& message)
{
if(!m_online || !checkBotProtection())
return;
m_protocolGame->sendTalk(channelType, 0, receiver, message);
m_protocolGame->sendTalk(speakTypeDesc, 0, receiver, message);
}
void Game::partyInvite(int creatureId)
@@ -408,7 +408,7 @@ void Game::partyShareExperience(bool active)
m_protocolGame->sendShareExperience(active, 0);
}
void Game::openOutfitWindow()
void Game::requestOutfit()
{
if(!m_online || !checkBotProtection())
return;
@@ -416,6 +416,22 @@ void Game::openOutfitWindow()
m_protocolGame->sendGetOutfit();
}
void Game::requestChannels()
{
if(!m_online || !checkBotProtection())
return;
m_protocolGame->sendGetChannels();
}
void Game::openChannel(int channelId)
{
if(!m_online || !checkBotProtection())
return;
m_protocolGame->sendOpenChannel(channelId);
}
void Game::setOutfit(const Outfit& outfit)
{
if(!m_online || !checkBotProtection())

View File

@@ -66,15 +66,17 @@ public:
void cancelFollow();
void rotate(const ThingPtr& thing);
void talk(const std::string& message);
void talkChannel(int channelType, int channelId, const std::string& message);
void talkPrivate(int channelType, const std::string& receiver, const std::string& message);
void talkChannel(const std::string& speakTypeDesc, int channelId, const std::string& message);
void talkPrivate(const std::string& speakTypeDesc, const std::string& receiver, const std::string& message);
void partyInvite(int creatureId);
void partyJoin(int creatureId);
void partyRevokeInvitation(int creatureId);
void partyPassLeadership(int creatureId);
void partyLeave();
void partyShareExperience(bool active);
void openOutfitWindow();
void requestOutfit();
void requestChannels();
void openChannel(int channelId);
void setOutfit(const Outfit& outfit);
void addVip(const std::string& name);
void removeVip(int playerId);

View File

@@ -55,6 +55,8 @@ public:
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
double getLevel() { return getStatistic(Otc::Level); }
private:
bool m_canReportBugs;
bool m_clientWalking;

View File

@@ -145,6 +145,7 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<LocalPlayer, Player>();
g_lua.bindClassMemberFunction<LocalPlayer>("getAttackingCreature", &LocalPlayer::getAttackingCreature);
g_lua.bindClassMemberFunction<LocalPlayer>("getFollowingCreature", &LocalPlayer::getFollowingCreature);
g_lua.bindClassMemberFunction<LocalPlayer>("getLevel", &LocalPlayer::getLevel);
g_lua.registerClass<Tile>();
g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean);
@@ -177,7 +178,9 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("logout", std::bind(&Game::logout, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("cancelLogin", std::bind(&Game::cancelLogin, &g_game));
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
g_lua.bindClassStaticFunction<Game>("openOutfitWindow", std::bind(&Game::openOutfitWindow, &g_game));
g_lua.bindClassStaticFunction<Game>("requestOutfit", std::bind(&Game::requestOutfit, &g_game));
g_lua.bindClassStaticFunction<Game>("requestChannels", std::bind(&Game::requestChannels, &g_game));
g_lua.bindClassStaticFunction<Game>("openChannel", std::bind(&Game::openChannel, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("open", std::bind(&Game::open, &g_game, _1, _2));

View File

@@ -336,6 +336,43 @@ namespace Proto {
}
}
inline int translateSpeakTypeDesc(const std::string& type) {
if(type == "say")
return Proto::SpeakSay;
else if(type == "whisper")
return Proto::SpeakWhisper;
else if(type == "yell")
return Proto::SpeakYell;
else if(type == "monsterSay")
return Proto::SpeakMonsterSay;
else if(type == "monsterYell")
return Proto::SpeakMonsterYell;
else if(type == "npcToPlayer")
return Proto::SpeakPrivateNpcToPlayer;
else if(type == "channelYellow")
return Proto::SpeakChannelYellow;
else if(type == "channelWhite")
return Proto::SpeakChannelWhite;
else if(type == "channelRed")
return Proto::SpeakChannelRed;
else if(type == "channelRed")
return Proto::SpeakChannelRed2;
else if(type == "channelOrange")
return Proto::SpeakChannelOrange;
else if(type == "private")
return Proto::SpeakPrivate;
else if(type == "playerToNpc")
return Proto::SpeakPrivatePlayerToNpc;
else if(type == "broadcast")
return Proto::SpeakBroadcast;
else if(type == "privateRed")
return Proto::SpeakPrivateRed;
else {
logError("unknown protocol speak type desc ", type);
return 0;
}
}
inline std::string translateTextMessageType(int type) {
switch(type) {
case Proto::MessageConsoleOrange:

View File

@@ -73,7 +73,7 @@ public:
void sendTextWindow(uint windowTextId, const std::string& text);
void sendHouseWindow(int doorId, uint id, const std::string& text);
void sendLookAt(const Position& position, int thingId, int stackpos);
void sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message);
void sendTalk(const std::string& speakTypeDesc, int channelId, const std::string& receiver, const std::string& message);
void sendGetChannels();
void sendJoinChannel(int channelId);
void sendLeaveChannel(int channelId);
@@ -88,7 +88,7 @@ public:
void sendPassLeadership(uint creatureId);
void sendLeaveParty();
void sendShareExperience(bool active, int unknown);
void sendOpenChannel();
void sendOpenChannel(int channelId);
void sendInviteToChannel(const std::string& name);
void sendExcludeFromChannel(const std::string& name);
void sendCancel();

View File

@@ -341,18 +341,18 @@ void ProtocolGame::sendLookAt(const Position& position, int thingId, int stackpo
send(oMsg);
}
void ProtocolGame::sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message)
void ProtocolGame::sendTalk(const std::string& speakTypeDesc, int channelId, const std::string& receiver, const std::string& message)
{
if(message.length() > 255 || message.length() <= 0)
return;
int speakType = Proto::translateSpeakTypeDesc(speakTypeDesc);
OutputMessage oMsg;
oMsg.addU8(Proto::ClientTalk);
oMsg.addU8(speakType);
assert(channelType >= 0);
oMsg.addU8(channelType);
switch(channelType) {
switch(speakType) {
case Proto::SpeakPrivate:
case Proto::SpeakPrivateRed:
oMsg.addString(receiver);
@@ -486,10 +486,11 @@ void ProtocolGame::sendShareExperience(bool active, int unknown)
send(oMsg);
}
void ProtocolGame::sendOpenChannel()
void ProtocolGame::sendOpenChannel(int channelId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientOpenChannel);
oMsg.addU16(channelId);
send(oMsg);
}