]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/servercommand.cpp
Move ClientMap to clientmap.{h,cpp}
[dragonfireclient.git] / src / servercommand.cpp
index 3c0e6d5108086f93c8505ec968fb86b9dfe84a82..e2e84bacb000945e4bf2ac08a392217cc8045fea 100644 (file)
@@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "servercommand.h"
 #include "utility.h"
 #include "settings.h"
+#include "main.h" // For g_settings
 
 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
 
@@ -221,7 +222,11 @@ void cmd_teleport(std::wostringstream &os,
                        <<PP(ctx->player->getPosition()/BS)<<" to "
                        <<PP(dest/BS)<<std::endl;
 
-       ctx->player->setPosition(dest);
+       //ctx->player->setPosition(dest);
+
+       // Use the ServerActiveObject interface of ServerRemotePlayer
+       ServerRemotePlayer *srp = static_cast<ServerRemotePlayer*>(ctx->player);
+       srp->setPos(dest);
        ctx->server->SendMovePlayer(ctx->player);
 
        os<< L"-!- Teleported.";
@@ -250,20 +255,19 @@ void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
                        os<<L"-!- No such player";
                        return;
                }
-
-               con::Peer *peer = ctx->server->getPeerNoEx(player->peer_id);
-               if(peer == NULL)
-               {
+               
+               try{
+                       Address address = ctx->server->getPeerAddress(player->peer_id);
+                       std::string ip_string = address.serializeString();
+                       ctx->server->setIpBanned(ip_string, player->getName());
+                       os<<L"-!- Banned "<<narrow_to_wide(ip_string)<<L"|"
+                                       <<narrow_to_wide(player->getName());
+
+                       actionstream<<ctx->player->getName()<<" bans "
+                                       <<player->getName()<<" / "<<ip_string<<std::endl;
+               } catch(con::PeerNotFoundException){
                        dstream<<__FUNCTION_NAME<<": peer was not found"<<std::endl;
-                       return;
                }
-               std::string ip_string = peer->address.serializeString();
-               ctx->server->setIpBanned(ip_string, player->getName());
-               os<<L"-!- Banned "<<narrow_to_wide(ip_string)<<L"|"
-                               <<narrow_to_wide(player->getName());
-
-               actionstream<<ctx->player->getName()<<" bans "
-                               <<player->getName()<<" / "<<ip_string<<std::endl;
        }
        else
        {
@@ -277,6 +281,87 @@ void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
        }
 }
 
+void cmd_setclearpassword(std::wostringstream &os,
+       ServerCommandContext *ctx)
+{
+       if((ctx->privs & PRIV_PASSWORD) == 0)
+       {
+               os<<L"-!- You don't have permission to do that";
+               return;
+       }
+
+       std::string playername;
+       std::wstring password;
+
+       if(ctx->parms[0] == L"setpassword")
+       {
+               if(ctx->parms.size() != 3)
+               {
+                       os<<L"-!- Missing parameter";
+                       return;
+               }
+
+               playername = wide_to_narrow(ctx->parms[1]);
+               password = ctx->parms[2];
+
+               actionstream<<ctx->player->getName()<<" sets password of "
+                       <<playername<<std::endl;
+       }
+       else
+       {
+               // clearpassword
+
+               if(ctx->parms.size() != 2)
+               {
+                       os<<L"-!- Missing parameter";
+                       return;
+               }
+
+               playername = wide_to_narrow(ctx->parms[1]);
+               password = L"";
+
+               actionstream<<ctx->player->getName()<<" clears password of"
+                       <<playername<<std::endl;
+       }
+
+       ctx->server->setPlayerPassword(playername, password);
+
+       std::wostringstream msg;
+       msg<<ctx->player->getName()<<L" changed your password";
+       ctx->server->notifyPlayer(playername.c_str(), msg.str());
+
+       os<<L"-!- Password change for "<<narrow_to_wide(playername)<<" successful";
+}
+
+void cmd_clearobjects(std::wostringstream &os,
+       ServerCommandContext *ctx)
+{
+       if((ctx->privs & PRIV_SERVER) ==0)
+       {
+               os<<L"-!- You don't have permission to do that";
+               return;
+       }
+
+       actionstream<<ctx->player->getName()
+                       <<" clears all objects"<<std::endl;
+       
+       {
+               std::wstring msg;
+               msg += L"Clearing all objects. This may take long.";
+               msg += L" You may experience a timeout. (by ";
+               msg += narrow_to_wide(ctx->player->getName());
+               msg += L")";
+               ctx->server->notifyPlayers(msg);
+       }
+
+       ctx->env->clearAllObjects();
+                                       
+       actionstream<<"object clearing done"<<std::endl;
+       
+       os<<L"*** cleared all objects";
+       ctx->flags |= SEND_TO_OTHERS;
+}
+
 
 std::wstring processServerCommand(ServerCommandContext *ctx)
 {
@@ -289,9 +374,9 @@ std::wstring processServerCommand(ServerCommandContext *ctx)
        if(ctx->parms.size() == 0 || ctx->parms[0] == L"help")
        {
                os<<L"-!- Available commands: ";
-               os<<L"status privs ";
+               os<<L"me status privs";
                if(privs & PRIV_SERVER)
-                       os<<L"shutdown setting ";
+                       os<<L" shutdown setting clearobjects";
                if(privs & PRIV_SETTIME)
                        os<<L" time";
                if(privs & PRIV_TELEPORT)
@@ -300,47 +385,34 @@ std::wstring processServerCommand(ServerCommandContext *ctx)
                        os<<L" grant revoke";
                if(privs & PRIV_BAN)
                        os<<L" ban unban";
+               if(privs & PRIV_PASSWORD)
+                       os<<L" setpassword clearpassword";
        }
        else if(ctx->parms[0] == L"status")
-       {
                cmd_status(os, ctx);
-       }
        else if(ctx->parms[0] == L"privs")
-       {
                cmd_privs(os, ctx);
-       }
        else if(ctx->parms[0] == L"grant" || ctx->parms[0] == L"revoke")
-       {
                cmd_grantrevoke(os, ctx);
-       }
        else if(ctx->parms[0] == L"time")
-       {
                cmd_time(os, ctx);
-       }
        else if(ctx->parms[0] == L"shutdown")
-       {
                cmd_shutdown(os, ctx);
-       }
        else if(ctx->parms[0] == L"setting")
-       {
                cmd_setting(os, ctx);
-       }
        else if(ctx->parms[0] == L"teleport")
-       {
                cmd_teleport(os, ctx);
-       }
        else if(ctx->parms[0] == L"ban" || ctx->parms[0] == L"unban")
-       {
                cmd_banunban(os, ctx);
-       }
+       else if(ctx->parms[0] == L"setpassword" || ctx->parms[0] == L"clearpassword")
+               cmd_setclearpassword(os, ctx);
        else if(ctx->parms[0] == L"me")
-       {
                cmd_me(os, ctx);
-       }
+       else if(ctx->parms[0] == L"clearobjects")
+               cmd_clearobjects(os, ctx);
        else
-       {
                os<<L"-!- Invalid command: " + ctx->parms[0];
-       }
+       
        return os.str();
 }