Ir para conteúdo

[C++] TV SYSTEM


Kevick

Posts Recomendados

Em 16/03/2017 em 09:46, Kevick disse:

 

 

 

TV System é um sistema que possibilita players assistirem outros jogadores pela tv em seu servidor, bom eu só irei deixar á parte dos códigos aqui vocês terão que desenvolver os scripts em lua para funcionar porém os códigos estão prontos e funcionais.

 

 

 

 

 

 

 

 

 

em luascript.cpp adicione:

 

 

 

Spoiler

 

  Ocultar conteúdo

 

 

 



 

 

//getCreatureNoMove(cid)

lua_register(m_luaState, "getCreatureNoMove", LuaScriptInterface::luaGetCreatureNoMove);

 

//doCreatureSetNoMove(cid, block)

lua_register(m_luaState, "doCreatureSetNoMove", LuaScriptInterface::luaDoCreatureSetNoMove);

 

//doInviteToPrivateChannel(cid, msg)

lua_register(m_luaState, "doInviteToPrivateChannel", LuaScriptInterface::luaDoInviteToPrivateChannel);

 

//doRemoveIntoPrivateChannel(cid, msg)

lua_register(m_luaState, "doRemoveIntoPrivateChannel", LuaScriptInterface::luaDoRemoveIntoPrivateChannel);

 

//doDeletePrivateChannel(cid)

lua_register(m_luaState, "doDeletePrivateChannel", LuaScriptInterface::luaDoDeletePrivateChannel);

 

//getCreatureHideHealth(cid)

lua_register(m_luaState, "getCreatureHideHealth", LuaScriptInterface::luaGetCreatureHideHealth);

 

//doCreatureSetHideHealth(cid, hide)

lua_register(m_luaState, "doCreatureSetHideHealth", LuaScriptInterface::luaDoCreatureSetHideHealth);

 

//doCreatePrivateChannel(cid)

lua_register(m_luaState, "doCreatePrivateChannel", LuaScriptInterface::luaDoCreatePrivateChannel);

 

 

 

 

 

ainda em luascript.cpp:

 

 

 

Spoiler

 

  Mostrar conteúdo oculto

 

 

 



 

 

int32_t LuaScriptInterface::luaGetCreatureHideHealth(lua_State* L)

{

//getCreatureHideHealth(cid)

ScriptEnviroment* env = getEnv();

 

if(Creature* creature = env->getCreatureByUID(popNumber(L)))

lua_pushboolean(L, creature->getHideHealth());

else

{

errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));

lua_pushboolean(L, false);

}

return 1;

}

 

int32_t LuaScriptInterface::luaDoCreatureSetHideHealth(lua_State* L)

{

//doCreatureSetHideHealth(cid, hide)

bool hide = popNumber(L);

 

ScriptEnviroment* env = getEnv();

if(Creature* creature = env->getCreatureByUID(popNumber(L)))

{

creature->setHideHealth(hide);

g_game.addCreatureHealth(creature);

lua_pushboolean(L, true);

}

else

{

errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));

lua_pushboolean(L, false);

}

return 1;

}

 

int32_t LuaScriptInterface::luaDoRemoveIntoPrivateChannel(lua_State* L)

{

//doRemoveIntoPrivateChannel(cid, string)

std::string name = popString(L);

uint32_t cid = popNumber(L);

 

ScriptEnviroment* env = getEnv();

if(Player* player = env->getPlayerByUID(cid))

{

if(g_game.playerChannelExclude(player->getID(), name))

lua_pushboolean(L, true);

else

lua_pushboolean(L, false);

}

else

{

errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));

lua_pushboolean(L, false);

}

 

return 1;

}

 

int32_t LuaScriptInterface::luaDoDeletePrivateChannel(lua_State* L)

{

//doDeletePrivateChannel(cid)

uint32_t cid = popNumber(L);

 

ScriptEnviroment* env = getEnv();

if(Player* player = env->getPlayerByUID(cid))

{

if(g_chat.deleteChannel(player, g_chat.getPrivateChannel(player)->getId()))

lua_pushboolean(L, true);

else

lua_pushboolean(L, false);

}

else

{

errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));

lua_pushboolean(L, false);

}

 

return 1;

}

 

 

int32_t LuaScriptInterface::luaDoInviteToPrivateChannel(lua_State* L)

{

//doCreatePrivateChannel(cid)

std::string name = popString(L);

uint32_t cid = popNumber(L);

 

ScriptEnviroment* env = getEnv();

if(Player* player = env->getPlayerByUID(cid))

{

if(g_game.playerChannelInvite(player->getID(), name))

lua_pushboolean(L, true);

else

lua_pushboolean(L, false);

}

else

{

errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));

lua_pushboolean(L, false);

}

 

return 1;

}

 

int32_t LuaScriptInterface::luaDoCreatePrivateChannel(lua_State* L)

{

//doCreatePrivateChannel(cid)

//std::string loot = popString(L);

uint32_t cid = popNumber(L);

 

ScriptEnviroment* env = getEnv();

if(Player* player = env->getPlayerByUID(cid))

{

if(g_game.playerCreatePrivateChannel(player->getID()))

lua_pushboolean(L, true);

else

lua_pushboolean(L, false);

}

else

{

errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));

lua_pushboolean(L, false);

}

 

return 1;

}

 

int32_t LuaScriptInterface::luaDoCreatureSetNoMove(lua_State* L)

{

//doCreatureSetNoMove(cid, block)

bool block = popNumber(L);

 

ScriptEnviroment* env = getEnv();

if(Creature* creature = env->getCreatureByUID(popNumber(L)))

{

creature->setNoMove(block);

lua_pushboolean(L, true);

}

else

{

errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));

lua_pushboolean(L, false);

}

 

return 1;

}

 

int32_t LuaScriptInterface::luaGetCreatureNoMove(lua_State* L)

{

//getCreatureNoMove(cid)

ScriptEnviroment* env = getEnv();

if(Creature* creature = env->getCreatureByUID(popNumber(L)))

lua_pushboolean(L, creature->getNoMove());

else

{

errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));

lua_pushboolean(L, false);

}

 

return 1;

}

 

 

 

 

 

agora em luascript.h adicione:

 

 

 

Spoiler

 

  Ocultar conteúdo

 

 

 



 

 

static int32_t luaDoCreatePrivateChannel(lua_State* L);

static int32_t luaDoInviteToPrivateChannel(lua_State* L);

static int32_t luaDoRemoveIntoPrivateChannel(lua_State* L);

static int32_t luaDoDeletePrivateChannel(lua_State* L);

static int32_t luaGetCreatureNoMove(lua_State* L);

static int32_t luaDoCreatureSetNoMove(lua_State* L);

static int32_t luaGetCreatureHideHealth(lua_State* L);

static int32_t luaDoCreatureSetHideHealth(lua_State* L);

 

 

 

 

 

agora vai em chat.cpp e adicione:

 

 

 

Spoiler

 

  Ocultar conteúdo

 

 

 



 

 

ChatChannel* Chat::createChannel(Player* player, uint16_t channelId) // tv cam system

{

if(!player || player->isRemoved() || getChannel(player, channelId))

return NULL;

 

switch(channelId)

{

case CHANNEL_GUILD:

{

ChatChannel* newChannel = NULL;

if((newChannel = new ChatChannel(channelId, player->getGuildName(), ChatChannel::staticFlags)))

m_guildChannels[player->getGuildId()] = newChannel;

 

return newChannel;

}

 

case CHANNEL_PARTY:

{

ChatChannel* newChannel = NULL;

if(player->getParty() && (newChannel = new ChatChannel(channelId, partyName, ChatChannel::staticFlags)))

m_partyChannels[player->getParty()] = newChannel;

 

return newChannel;

}

 

case CHANNEL_PRIVATE:

{

//only 1 private channel for each premium player

if(!player->isPremium() || getPrivateChannel(player))

return NULL;

 

//find a free private channel slot

for(uint16_t i = 100; i < 10000; ++i)

{

if(m_privateChannels.find(i) != m_privateChannels.end())

continue;

 

uint16_t flags = 0;

if(dummyPrivate)

flags = dummyPrivate->getFlags();

 

PrivateChatChannel* newChannel = NULL;

//std::stringstream msg; = "Canal " + (player->getSex(false) ? "do " : "da ") + player->getName();

if((newChannel = new PrivateChatChannel(i, player->getName() + "'s channels", ChatChannel::staticFlags)))

{

newChannel->setOwner(player->getGUID());

m_privateChannels = newChannel;

}

 

return newChannel;

}

}

 

default:

break;

}

 

return NULL;

}

 

 

 

 

 

depois vá em chat.h e adicione:

 

 

 

Spoiler

 

  Ocultar conteúdo

 

 

 



 

 

class Player;

enum ChannelFlags_t

{

CHANNELFLAG_NONE = 0,

CHANNELFLAG_ENABLED = 1 << 0,

CHANNELFLAG_ACTIVE = 1 << 1,

CHANNELFLAG_LOGGED = 1 << 2,

};

 

typedef std::map<uint32_t, Player*> UsersMap;

typedef std::list<uint32_t> InviteList;

 

class ChatChannel

{

public:

ChatChannel(uint16_t id, const std::string& name, uint16_t flags, uint32_t access = 0,

uint32_t level = 1, Condition* condition = NULL, int32_t conditionId = -1,

const std::string& conditionMessage = "", VocationMap* vocationMap = NULL);

virtual ~ChatChannel()

{

if(m_condition)

delete m_condition;

 

if(m_vocationMap)

delete m_vocationMap;

}

static uint16_t staticFlags;

 

uint16_t getId() const {return m_id;}

const std::string& getName() const {return m_name;}

uint16_t getFlags() const {return m_flags;}

 

int32_t getConditionId() const {return m_conditionId;}

const std::string& getConditionMessage() const {return m_conditionMessage;}

const UsersMap& getUsers() {return m_users;}

 

uint32_t getLevel() const {return m_level;}

uint32_t getAccess() const {return m_access;}

virtual const uint32_t getOwner() {return 0;}

 

bool hasFlag(uint16_t value) const {return ((m_flags & (uint16_t)value) == (uint16_t)value);}

bool checkVocation(uint32_t vocationId) const

{return !m_vocationMap || m_vocationMap->empty() || m_vocationMap->find(

vocationId) != m_vocationMap->end();}

 

bool addUser(Player* player);

bool removeUser(Player* player);

 

bool talk(Player* player, SpeakClasses type, const std::string& text, uint32_t _time = 0);

 

protected:

uint16_t m_id, m_flags;

int32_t m_conditionId;

uint32_t m_access, m_level;

std::string m_name, m_conditionMessage;

 

Condition* m_condition;

VocationMap* m_vocationMap;

 

UsersMap m_users;

boost::shared_ptr<std::ofstream> m_file;

};

 

class Chat

{

public:

Chat(): statement(0), dummyPrivate(NULL), partyName("Party") {}

virtual ~Chat();

 

bool reload();

bool loadFromXml();

bool parseChannelNode(xmlNodePtr p);

 

ChatChannel* createChannel(Player* player, uint16_t channelId);

bool deleteChannel(Player* player, uint16_t channelId);

 

ChatChannel* addUserToChannel(Player* player, uint16_t channelId);

bool removeUserFromChannel(Player* player, uint16_t channelId);

void removeUserFromAllChannels(Player* player);

 

bool talkToChannel(Player* player, SpeakClasses type, const std::string& text, uint16_t channelId);

 

ChatChannel* getChannel(Player* player, uint16_t channelId);

ChatChannel* getChannelById(uint16_t channelId);

 

std::string getChannelName(Player* player, uint16_t channelId);

ChannelList getChannelList(Player* player);

 

PrivateChatChannel* getPrivateChannel(Player* player);

bool isPrivateChannel(uint16_t channelId) const {return m_privateChannels.find(channelId) != m_privateChannels.end();}

 

uint32_t statement;

StatementMap statementMap;

 

private:

void clear();

 

typedef std::map<uint16_t, ChatChannel*> NormalChannelMap;

NormalChannelMap m_normalChannels;

 

typedef std::map<uint16_t, PrivateChatChannel*> PrivateChannelMap;

PrivateChannelMap m_privateChannels;

 

typedef std::map<Party*, ChatChannel*> PartyChannelMap;

PartyChannelMap m_partyChannels;

 

typedef std::map<uint32_t, ChatChannel*> GuildChannelMap;

GuildChannelMap m_guildChannels;

 

ChatChannel* dummyPrivate;

std::string partyName;

};

 

 

 

 

 

agora em game.cpp adicione:

 

 

 

Spoiler

 

  Ocultar conteúdo

 

 

 



 

 

bool Game::playerBroadcastMessage(Player* player, SpeakClasses type, const std::string& text)

{

if(!player->hasFlag(PlayerFlag_CanBroadcast) || type < SPEAK_CLASS_FIRST || type > SPEAK_CLASS_LAST)

return false;

 

for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)

it->second->sendCreatureSay(player, type, text);

 

//TODO: event handling - onCreatureSay

std::cout << "> " << player->getName() << " broadcasted: \"" << text << "\"." << std::endl;

return true;

}

 

bool Game::playerCreatePrivateChannel(uint32_t playerId)

{

Player* player = getPlayerByID(playerId);

if(!player || player->isRemoved() || !player->isPremium())

return false;

 

ChatChannel* channel = g_chat.createChannel(player, 0xFFFF);

if(!channel || !channel->addUser(player))

return false;

 

player->sendCreatePrivateChannel(channel->getId(), channel->getName());

return true;

}

 

bool Game::playerChannelInvite(uint32_t playerId, const std::string& name)

{

Player* player = getPlayerByID(playerId);

if(!player || player->isRemoved())

return false;

 

Player* invitePlayer = getPlayerByName(name);

if(!invitePlayer)

return false;

 

PrivateChatChannel* channel = g_chat.getPrivateChannel(player);

if(!channel)

return false;

 

channel->invitePlayer(player, invitePlayer);

channel->addInvited(invitePlayer);

 

ChatChannel* teste = (ChatChannel*) channel; teste->addUser(invitePlayer);

 

invitePlayer->sendChannel(channel->getId(), channel->getName());

return true;

}

 

bool Game::playerChannelExclude(uint32_t playerId, const std::string& name)

{

Player* player = getPlayerByID(playerId);

if(!player || player->isRemoved())

return false;

 

PrivateChatChannel* channel = g_chat.getPrivateChannel(player);

if(!channel)

return false;

 

Player* excludePlayer = getPlayerByName(name);

if(!excludePlayer)

return false;

 

if (player->getID() == excludePlayer->getID()){

g_chat.deleteChannel(player, g_chat.getPrivateChannel(player)->getId());

return true;

}

 

channel->excludePlayer(player, excludePlayer);

return true;

}

 

bool Game::playerRequestChannels(uint32_t playerId)

{

Player* player = getPlayerByID(playerId);

if(!player || player->isRemoved())

return false;

 

player->sendChannelsDialog();

return true;

}

 

bool Game::playerOpenChannel(uint32_t playerId, uint16_t channelId)

{

Player* player = getPlayerByID(playerId);

if(!player || player->isRemoved())

return false;

 

ChatChannel* channel = g_chat.addUserToChannel(player, channelId);

if(!channel)

{

#ifdef __DEBUG_CHAT__

std::cout << "Game::playerOpenChannel - failed adding user to channel." << std::endl;

#endif

return false;

}

 

if(channel->getId() != CHANNEL_RVR)

player->sendChannel(channel->getId(), channel->getName());

else

player->sendRuleViolationsChannel(channel->getId());

 

return true;

}

 

bool Game::playerCloseChannel(uint32_t playerId, uint16_t channelId)

{

Player* player = getPlayerByID(playerId);

if(!player || player->isRemoved())

return false;

 

g_chat.removeUserFromChannel(player, channelId);

return true;

}

 

bool Game::playerOpenPrivateChannel(uint32_t playerId, std::string& receiver)

{

Player* player = getPlayerByID(playerId);

if(!player || player->isRemoved())

return false;

 

if(IOLoginData::getInstance()->playerExists(receiver))

player->sendOpenPrivateChannel(receiver);

else

player->sendCancel("A player with this name does not exist.");

 

return true;

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Créditos

 

 

 

 

Eu (Por postar aqui no EKZ)

 

 

 

 

Lordbaxx

 

 

 

 

Smix

 

 

 

 

errorrr

 

 

errrrrrrraaaaa.thumb.png.f03151acec781a3e320a6ec26752db1d.png

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...