ok
This commit is contained in:
@@ -27,13 +27,13 @@ std::string CommandBan::execute(Minecraft& mc, Player& player, const std::vector
|
|||||||
return lower == nicknameLower;
|
return lower == nicknameLower;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (*it == (Player*)mc.player) {
|
|
||||||
return "ban: you can't ban urself lol";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto sourceId = (*it)->owner;
|
|
||||||
|
|
||||||
if (it != mc.level->players.end()) {
|
if (it != mc.level->players.end()) {
|
||||||
|
if (*it == (Player*)mc.player) {
|
||||||
|
return "banip: you can't ban urself lol";
|
||||||
|
}
|
||||||
|
|
||||||
|
auto sourceId = (*it)->owner;
|
||||||
|
|
||||||
(*it)->reallyRemoveIfPlayer = true;
|
(*it)->reallyRemoveIfPlayer = true;
|
||||||
mc.level->removeEntity((*it));
|
mc.level->removeEntity((*it));
|
||||||
mc.raknetInstance->getPeer()->CloseConnection(sourceId, true);
|
mc.raknetInstance->getPeer()->CloseConnection(sourceId, true);
|
||||||
|
|||||||
@@ -27,17 +27,22 @@ std::string CommandBanIp::execute(Minecraft& mc, Player& player, const std::vect
|
|||||||
return lower == nicknameLower;
|
return lower == nicknameLower;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (*it == (Player*)mc.player) {
|
std::string clientIp;
|
||||||
return "banip: you can't ban urself lol";
|
|
||||||
}
|
|
||||||
|
|
||||||
RakNet::SystemAddress sysAddress = mc.raknetInstance->getPeer()->GetSystemAddressFromGuid((*it)->owner);
|
|
||||||
|
|
||||||
char clientIp[32];
|
|
||||||
sysAddress.ToString(false, clientIp);
|
|
||||||
auto sourceId = (*it)->owner;
|
|
||||||
|
|
||||||
if (it != mc.level->players.end()) {
|
if (it != mc.level->players.end()) {
|
||||||
|
if (*it == (Player*)mc.player) {
|
||||||
|
return "banip: you can't ban urself lol";
|
||||||
|
}
|
||||||
|
|
||||||
|
RakNet::SystemAddress sysAddress = mc.raknetInstance->getPeer()->GetSystemAddressFromGuid((*it)->owner);
|
||||||
|
|
||||||
|
char ip[32];
|
||||||
|
sysAddress.ToString(false, ip);
|
||||||
|
|
||||||
|
clientIp = ip;
|
||||||
|
|
||||||
|
auto sourceId = (*it)->owner;
|
||||||
|
|
||||||
(*it)->reallyRemoveIfPlayer = true;
|
(*it)->reallyRemoveIfPlayer = true;
|
||||||
mc.level->removeEntity((*it));
|
mc.level->removeEntity((*it));
|
||||||
mc.raknetInstance->getPeer()->CloseConnection(sourceId, true);
|
mc.raknetInstance->getPeer()->CloseConnection(sourceId, true);
|
||||||
@@ -47,6 +52,8 @@ std::string CommandBanIp::execute(Minecraft& mc, Player& player, const std::vect
|
|||||||
return args[0] + " already banned!";
|
return args[0] + " already banned!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clientIp = args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
mc.level->bannedIps.insert(clientIp);
|
mc.level->bannedIps.insert(clientIp);
|
||||||
|
|||||||
@@ -35,9 +35,11 @@ std::string CommandKick::execute(Minecraft& mc, Player& player, const std::vecto
|
|||||||
return "kick: you can't kick urself lol";
|
return "kick: you can't kick urself lol";
|
||||||
}
|
}
|
||||||
|
|
||||||
mc.level->removePlayer(*it);
|
auto sourceId = (*it)->owner;
|
||||||
(*it)->remove();
|
|
||||||
mc.raknetInstance->getPeer()->CloseConnection((*it)->owner, true);
|
(*it)->reallyRemoveIfPlayer = true;
|
||||||
|
mc.level->removeEntity((*it));
|
||||||
|
mc.raknetInstance->getPeer()->CloseConnection(sourceId, true);
|
||||||
return "kick: successfully kicked player " + args[0];
|
return "kick: successfully kicked player " + args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "commands/CommandOp.hpp"
|
#include "commands/CommandOp.hpp"
|
||||||
#include "commands/CommandBan.hpp"
|
#include "commands/CommandBan.hpp"
|
||||||
#include "commands/CommandBanIp.hpp"
|
#include "commands/CommandBanIp.hpp"
|
||||||
|
#include "commands/CommandPardon.hpp"
|
||||||
#include "network/packet/ChatPacket.h"
|
#include "network/packet/ChatPacket.h"
|
||||||
#include "network/RakNetInstance.h"
|
#include "network/RakNetInstance.h"
|
||||||
#include "world/level/Level.h"
|
#include "world/level/Level.h"
|
||||||
@@ -23,6 +24,7 @@ void CommandManager::registerAllCommands() {
|
|||||||
m_commands.push_back(new CommandOp());
|
m_commands.push_back(new CommandOp());
|
||||||
m_commands.push_back(new CommandBan());
|
m_commands.push_back(new CommandBan());
|
||||||
m_commands.push_back(new CommandBanIp());
|
m_commands.push_back(new CommandBanIp());
|
||||||
|
m_commands.push_back(new CommandPardon());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> CommandManager::getListAllCommands() {
|
std::vector<std::string> CommandManager::getListAllCommands() {
|
||||||
|
|||||||
40
src/commands/CommandPardon.cpp
Normal file
40
src/commands/CommandPardon.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include "CommandPardon.hpp"
|
||||||
|
#include "commands/Command.hpp"
|
||||||
|
#include "network/RakNetInstance.h"
|
||||||
|
#include "raknet/RakPeerInterface.h"
|
||||||
|
#include "world/level/Level.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <client/Minecraft.h>
|
||||||
|
|
||||||
|
CommandPardon::CommandPardon() : Command("pardon") {}
|
||||||
|
|
||||||
|
std::string CommandPardon::execute(Minecraft& mc, Player& player, const std::vector<std::string>& args) {
|
||||||
|
if (!isPlayerOp(mc, player)) {
|
||||||
|
return "You aren't enough priveleged to run this command";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.empty()) {
|
||||||
|
return help(mc);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string nicknameLower = args[0];
|
||||||
|
std::transform(nicknameLower.begin(), nicknameLower.end(), nicknameLower.begin(), ::tolower);
|
||||||
|
|
||||||
|
if (mc.level->bannedPpl.find(nicknameLower) != mc.level->bannedPpl.end()) {
|
||||||
|
mc.level->bannedPpl.erase(nicknameLower);
|
||||||
|
|
||||||
|
return "pardon: successfully unbanned player " + args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mc.level->bannedIps.find(nicknameLower) != mc.level->bannedIps.end()) {
|
||||||
|
mc.level->bannedIps.erase(nicknameLower);
|
||||||
|
|
||||||
|
return "pardon: successfully unbanned ip " + args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Player/Ip doesnt banned";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CommandPardon::help(Minecraft& mc) {
|
||||||
|
return "Usage: /pardon <player>";
|
||||||
|
}
|
||||||
9
src/commands/CommandPardon.hpp
Normal file
9
src/commands/CommandPardon.hpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "Command.hpp"
|
||||||
|
|
||||||
|
class CommandPardon : public Command {
|
||||||
|
public:
|
||||||
|
CommandPardon();
|
||||||
|
|
||||||
|
std::string execute(Minecraft& mc, Player& player, const std::vector<std::string>& args);
|
||||||
|
std::string help(Minecraft& mc);
|
||||||
|
};
|
||||||
@@ -173,6 +173,7 @@ bool RakNetInstance::isMyLocalGuid(const RakNet::RakNetGUID& guid)
|
|||||||
void RakNetInstance::runEvents(NetEventCallback* callback)
|
void RakNetInstance::runEvents(NetEventCallback* callback)
|
||||||
{
|
{
|
||||||
RakNet::Packet* currentEvent;
|
RakNet::Packet* currentEvent;
|
||||||
|
bool disconnect = false;
|
||||||
|
|
||||||
while ((currentEvent = rakPeer->Receive()) != NULL)
|
while ((currentEvent = rakPeer->Receive()) != NULL)
|
||||||
{
|
{
|
||||||
@@ -200,6 +201,7 @@ void RakNetInstance::runEvents(NetEventCallback* callback)
|
|||||||
case ID_DISCONNECTION_NOTIFICATION:
|
case ID_DISCONNECTION_NOTIFICATION:
|
||||||
case ID_CONNECTION_LOST:
|
case ID_CONNECTION_LOST:
|
||||||
callback->onDisconnect(currentEvent->guid);
|
callback->onDisconnect(currentEvent->guid);
|
||||||
|
disconnect = true;
|
||||||
break;
|
break;
|
||||||
case ID_UNCONNECTED_PONG:
|
case ID_UNCONNECTED_PONG:
|
||||||
{
|
{
|
||||||
@@ -233,8 +235,9 @@ void RakNetInstance::runEvents(NetEventCallback* callback)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!disconnect) {
|
||||||
rakPeer->DeallocatePacket(currentEvent);
|
rakPeer->DeallocatePacket(currentEvent);
|
||||||
|
}
|
||||||
//delete activeBitStream;
|
//delete activeBitStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,9 +175,14 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, MessageP
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// @todo rewrite
|
||||||
displayGameMessage("<" + player->name + "> " + msg);
|
bool shouldShow = true;
|
||||||
|
|
||||||
PluginsManager::get().emit("Message", LuaPlayer(source), packet->message);
|
PluginsManager::get().emit("Message", LuaPlayer(source), packet->message);
|
||||||
|
|
||||||
|
if (shouldShow) {
|
||||||
|
displayGameMessage("<" + player->name + "> " + msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChatPacket* packet)
|
void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChatPacket* packet)
|
||||||
|
|||||||
Reference in New Issue
Block a user