Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Change Server::FreeInstance() to static
Browse files Browse the repository at this point in the history
  • Loading branch information
vexyl committed Sep 9, 2018
1 parent 03a9e90 commit c475c40
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/LuaPlugins/LuaPluginAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void LuaServer::Init(lua_State* L)
.addFunction("SetChatMute", &Client::SetChatMute)
.addFunction("GetUserType", &Client::GetUserType)
.addFunction("CanBuild", &Client::CanBuild)
.addFunction("GetName", &Client::GetName)
.addFunction("SetChatName", &Client::SetChatName)
.addFunction("GetChatName", &Client::GetChatName)
.endClass()
Expand Down Expand Up @@ -314,6 +315,21 @@ luabridge::LuaRef cmsgp_to_luatable(const struct Protocol::cmsgp clientMsg)
return table;
}

luabridge::LuaRef cposp_to_luatable(const struct Protocol::cposp clientPos)
{
luabridge::LuaRef table(LuaPluginHandler::L);
table = luabridge::newTable(LuaPluginHandler::L);

table["pid"] = clientPos.pid;
table["x"] = clientPos.pos.x;
table["y"] = clientPos.pos.y;
table["z"] = clientPos.pos.z;
table["yaw"] = clientPos.yaw;
table["pitch"] = clientPos.pitch;

return table;
}

luabridge::LuaRef cblockp_to_luatable(const struct Protocol::cblockp clientBlock)
{
luabridge::LuaRef table(LuaPluginHandler::L);
Expand Down
1 change: 1 addition & 0 deletions src/LuaPlugins/LuaPluginAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct LuaServer {
luabridge::LuaRef make_luatable();
luabridge::LuaRef cauthp_to_luatable(const struct Protocol::cauthp clientAuth);
luabridge::LuaRef cmsgp_to_luatable(const struct Protocol::cmsgp clientMsg);
luabridge::LuaRef cposp_to_luatable(const struct Protocol::cposp clientPos);
luabridge::LuaRef cblockp_to_luatable(const struct Protocol::cblockp clientBlock);

#endif // LUAPLUGINAPI_H_
2 changes: 1 addition & 1 deletion src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main()
}
}

server->FreeInstance();
Server::FreeInstance();

std::cout << "Exiting normally." << std::endl;

Expand Down
6 changes: 3 additions & 3 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ void Server::OnMessage(Client* client, struct Protocol::cmsgp clientMsg)

// Chat mute check--IsChatMuted() unmutes if timer expires
if (client->IsChatMuted()) {
LOG(LogLevel::kNormal, "[Muted (%s)] %s", name.c_str(), message.c_str());
LOG(LogLevel::kNormal, "[MUTED (%s)] %s", name.c_str(), message.c_str());
return;
}

// Is it a command or a chat message?
if (message.at(0) == '/') {
LOG(LogLevel::kNormal, "[Command (%s)] %s", name.c_str(), message.c_str());
LOG(LogLevel::kNormal, "[COMMAND (%s)] %s", name.c_str(), message.c_str());

// Strip leading '/'
std::string command = message.substr(1);
Expand Down Expand Up @@ -389,7 +389,7 @@ void Server::HandlePacket(Client* client, uint8_t opcode)
struct Protocol::cposp clientPos;

if (clientPos.Read(stream)) {
auto table = make_luatable();
auto table = cposp_to_luatable(clientPos);
m_pluginHandler.TriggerEvent(EventType::kOnPosition, client, table);

if (m_pluginHandler.GetEventFlag("NoDefaultCall") <= 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Server {
return m_thisPtr;
}

void FreeInstance();
static void FreeInstance();

void Init();

Expand Down

0 comments on commit c475c40

Please sign in to comment.