Added support for /kick
This commit is contained in:
parent
0d37fe3f4c
commit
7033689d72
@ -12,7 +12,7 @@ set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
|
||||
# Also remember to set PROTOCOL_VERSION in clientserver.h when releasing
|
||||
set(VERSION_MAJOR 0)
|
||||
set(VERSION_MINOR 1)
|
||||
set(VERSION_PATCH dev-20120430)
|
||||
set(VERSION_PATCH dev-20120501)
|
||||
if(VERSION_EXTRA)
|
||||
set(VERSION_PATCH ${VERSION_PATCH}-${VERSION_EXTRA})
|
||||
endif()
|
||||
|
@ -1378,6 +1378,12 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
||||
u8 oxygen = readU8(is);
|
||||
player->oxygen = oxygen;
|
||||
}
|
||||
else if(command == TOCLIENT_KICK)
|
||||
{
|
||||
ClientEvent event;
|
||||
event.type = CE_KICKED;
|
||||
m_client_event_queue.push_back(event);
|
||||
}
|
||||
else if(command == TOCLIENT_MOVE_PLAYER)
|
||||
{
|
||||
std::string datastring((char*)&data[2], datasize-2);
|
||||
|
@ -133,6 +133,7 @@ enum ClientEventType
|
||||
CE_NONE,
|
||||
CE_PLAYER_DAMAGE,
|
||||
CE_PLAYER_FORCE_MOVE,
|
||||
CE_KICKED,
|
||||
CE_DEATHSCREEN,
|
||||
CE_TEXTURES_UPDATED
|
||||
};
|
||||
|
@ -316,6 +316,11 @@ enum ToClientCommand
|
||||
u16 command
|
||||
u8 oxygen
|
||||
*/
|
||||
|
||||
TOCLIENT_KICK = 0x44,
|
||||
/*
|
||||
u16 command
|
||||
*/
|
||||
};
|
||||
|
||||
enum ToServerCommand
|
||||
|
@ -2125,6 +2125,10 @@ void the_game(
|
||||
camera_yaw = event.player_force_move.yaw;
|
||||
camera_pitch = event.player_force_move.pitch;
|
||||
}
|
||||
else if(event.type == CE_KICKED)
|
||||
{
|
||||
g_gamecallback->disconnect();
|
||||
}
|
||||
else if(event.type == CE_DEATHSCREEN)
|
||||
{
|
||||
if(respawn_menu_active)
|
||||
|
@ -3472,6 +3472,20 @@ void Server::SendOxygen(con::Connection &con, u16 peer_id, u8 oxygen)
|
||||
con.Send(peer_id, 0, data, true);
|
||||
}
|
||||
|
||||
void Server::SendKick(con::Connection &con, u16 peer_id)
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
|
||||
writeU16(os, TOCLIENT_KICK);
|
||||
|
||||
// Make data buffer
|
||||
std::string s = os.str();
|
||||
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
|
||||
// Send as reliable
|
||||
con.Send(peer_id, 0, data, true);
|
||||
}
|
||||
|
||||
|
||||
void Server::SendAccessDenied(con::Connection &con, u16 peer_id,
|
||||
const std::wstring &reason)
|
||||
@ -3663,6 +3677,14 @@ void Server::SendPlayerOxygen(u16 peer_id)
|
||||
SendOxygen(m_con, peer_id, playersao->getOxygen());
|
||||
}
|
||||
|
||||
void Server::SendPlayerKick(u16 peer_id)
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
PlayerSAO *playersao = getPlayerSAO(peer_id);
|
||||
assert(playersao);
|
||||
SendKick(m_con, peer_id);
|
||||
}
|
||||
|
||||
void Server::SendMovePlayer(u16 peer_id)
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
@ -558,6 +558,7 @@ public:
|
||||
std::string getWorldPath(){ return m_path_world; }
|
||||
|
||||
bool isSingleplayer(){ return m_simple_singleplayer_mode; }
|
||||
void SendPlayerKick(u16 peer_id);
|
||||
|
||||
void setAsyncFatalError(const std::string &error)
|
||||
{
|
||||
@ -579,6 +580,7 @@ private:
|
||||
static void SendHP(con::Connection &con, u16 peer_id, u8 hp);
|
||||
static void SendHunger(con::Connection &con, u16 peer_id, u8 hunger);
|
||||
static void SendOxygen(con::Connection &con, u16 peer_id, u8 oxygen);
|
||||
static void SendKick(con::Connection &con, u16 peer_id);
|
||||
static void SendAccessDenied(con::Connection &con, u16 peer_id,
|
||||
const std::wstring &reason);
|
||||
static void SendDeathscreen(con::Connection &con, u16 peer_id,
|
||||
|
@ -79,6 +79,33 @@ void cmd_shutdown(std::wostringstream &os,
|
||||
ctx->flags |= SEND_TO_OTHERS;
|
||||
}
|
||||
|
||||
void cmd_kick(std::wostringstream &os, ServerCommandContext *ctx)
|
||||
{
|
||||
if(!ctx->server->checkPriv(ctx->player->getName(), "basic_privs") &&
|
||||
!ctx->server->checkPriv(ctx->player->getName(), "privs"))
|
||||
{
|
||||
os<<L"-!- You don't have permission to do that";
|
||||
return;
|
||||
}
|
||||
if(ctx->parms.size() < 2)
|
||||
{
|
||||
os<<L"-!- Usage: /kick [playername]";
|
||||
}
|
||||
else
|
||||
{
|
||||
Player *player = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str());
|
||||
if(player == NULL)
|
||||
{
|
||||
os<<L"-!- Invalid player: "<<player->getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
ctx->server->SendPlayerKick(player->peer_id);
|
||||
os<<L"-!- Kicked "<<player->getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
|
||||
{
|
||||
if(!ctx->server->checkPriv(ctx->player->getName(), "ban"))
|
||||
@ -99,7 +126,7 @@ void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
|
||||
|
||||
if(player == NULL)
|
||||
{
|
||||
os<<L"-!- No such player";
|
||||
os<<L"-!- Invalid player: "<<player->getName();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -171,6 +198,8 @@ std::wstring processServerCommand(ServerCommandContext *ctx)
|
||||
cmd_time(os, ctx);
|
||||
else if(ctx->parms[0] == L"shutdown")
|
||||
cmd_shutdown(os, ctx);
|
||||
else if(ctx->parms[0] == L"kick")
|
||||
cmd_kick(os, ctx);
|
||||
else if(ctx->parms[0] == L"ban" || ctx->parms[0] == L"unban")
|
||||
cmd_banunban(os, ctx);
|
||||
else if(ctx->parms[0] == L"me")
|
||||
|
Loading…
x
Reference in New Issue
Block a user