Esempio n. 1
0
    public static void KickPlayer(ulong steamid, int duration = -1, string message = "HOST_KICKED_YOU")
    {
        BoltConnection connection;
        BoltEntity     playerEntity;

        MpPlayerList.GetConnectionAndEntity(steamid, out connection, out playerEntity);
        CoopKick.KickPlayer(connection, playerEntity, duration, message);
    }
Esempio n. 2
0
 public static bool ValidateSender(this GlobalEventListener listener, Event evnt, SenderTypes senderType = SenderTypes.Any)
 {
     return((CoopPeerStarter.Dedicated && evnt.RaisedBy == BoltNetwork.server) || evnt.RaisedBy == null || !(MpPlayerList.GetEntityFromBoltConnexion(evnt.RaisedBy) == null));
 }
Esempio n. 3
0
    public static void Recv(string command, string data, BoltConnection source)
    {
        if (CoopPeerStarter.DedicatedHost && source.IsDedicatedServerAdmin() && command != null)
        {
            if (CoopAdminCommand.< > f__switch$map2 == null)
            {
                CoopAdminCommand.< > f__switch$map2 = new Dictionary <string, int>(12)
                {
                    {
                        "save",
                        0
                    },
                    {
                        "restart",
                        1
                    },
                    {
                        "shutdown",
                        2
                    },
                    {
                        "openlogs",
                        3
                    },
                    {
                        "closelogs",
                        4
                    },
                    {
                        "kick",
                        5
                    },
                    {
                        "ban",
                        6
                    },
                    {
                        "unban",
                        7
                    },
                    {
                        "treeregrowmode",
                        8
                    },
                    {
                        "allowbuildingdestruction",
                        9
                    },
                    {
                        "allowenemiescreative",
                        10
                    },
                    {
                        "allowcheats",
                        11
                    }
                };
            }
            int num;
            if (CoopAdminCommand.< > f__switch$map2.TryGetValue(command, out num))
            {
                switch (num)
                {
                case 0:
                {
                    int slot;
                    if (!string.IsNullOrEmpty(data) && int.TryParse(data, out slot))
                    {
                        GameSetup.SetSlot((Slots)slot);
                    }
                    LevelSerializer.Checkpoint();
                    SaveSlotUtils.SaveHostGameGUID();
                    CoopAdminCommand.SendNetworkMessage("Game saved to slot " + (int)GameSetup.Slot, source);
                    break;
                }

                case 1:
                    CoopAdminCommand.SendNetworkMessageAll("Server shuting down for restart, please reconnect.");
                    TheForest.Utils.Scene.ActiveMB.StartCoroutine(CoopAdminCommand.ShutDownRoutine(true));
                    break;

                case 2:
                    CoopAdminCommand.SendNetworkMessageAll("Server is shuting down (no restart)");
                    TheForest.Utils.Scene.ActiveMB.StartCoroutine(CoopAdminCommand.ShutDownRoutine(false));
                    break;

                case 3:
                    if (!SteamDSConfig.ShowLogs)
                    {
                        ConsoleWriter.Open();
                        if (CoopAdminCommand.< > f__mg$cache0 == null)
                        {
                            CoopAdminCommand.< > f__mg$cache0 = new Application.LogCallback(CoopAdminCommand.Application_logMessageReceived);
                        }
                        Application.logMessageReceived += CoopAdminCommand.< > f__mg$cache0;
                        SteamDSConfig.ShowLogs          = true;
                        CoopAdminCommand.SendNetworkMessage("Opened logs console", source);
                    }
                    else
                    {
                        CoopAdminCommand.SendNetworkMessage("Error: console already opened", source);
                    }
                    break;

                case 4:
                    ConsoleWriter.Close();
                    if (CoopAdminCommand.< > f__mg$cache1 == null)
                    {
                        CoopAdminCommand.< > f__mg$cache1 = new Application.LogCallback(CoopAdminCommand.Application_logMessageReceived);
                    }
                    Application.logMessageReceived -= CoopAdminCommand.< > f__mg$cache1;
                    SteamDSConfig.ShowLogs          = false;
                    CoopAdminCommand.SendNetworkMessage("Closed logs console", source);
                    break;

                case 5:
                {
                    ulong num2;
                    if (ulong.TryParse(data, out num2))
                    {
                        BoltEntity entityFromSteamID = MpPlayerList.GetEntityFromSteamID(num2);
                        if (entityFromSteamID)
                        {
                            CoopKick.KickPlayer(entityFromSteamID, 1, "ADMIN_KICKED_YOU");
                            CoopAdminCommand.SendNetworkMessage("Kicked " + data, source);
                        }
                        else
                        {
                            CoopAdminCommand.SendNetworkMessage("Failed to kick " + data, source);
                        }
                    }
                    else
                    {
                        BoltEntity entityFromName = MpPlayerList.GetEntityFromName(data, source);
                        if (entityFromName)
                        {
                            CoopKick.KickPlayer(entityFromName, 1, "ADMIN_KICKED_YOU");
                            CoopAdminCommand.SendNetworkMessage("Kicked " + data, source);
                        }
                        else
                        {
                            CoopAdminCommand.SendNetworkMessage("Invalid SteamId or Name, kick failed (data=" + data + ")", source);
                        }
                    }
                    break;
                }

                case 6:
                {
                    ulong num2;
                    if (ulong.TryParse(data, out num2))
                    {
                        BoltEntity entityFromSteamID2 = MpPlayerList.GetEntityFromSteamID(num2);
                        if (entityFromSteamID2)
                        {
                            CoopKick.BanPlayer(entityFromSteamID2);
                            CoopAdminCommand.SendNetworkMessage("Banned " + data, source);
                        }
                        else
                        {
                            CoopAdminCommand.SendNetworkMessage("Failed to ban " + data, source);
                        }
                    }
                    else
                    {
                        BoltEntity entityFromName2 = MpPlayerList.GetEntityFromName(data, source);
                        if (entityFromName2)
                        {
                            CoopKick.BanPlayer(entityFromName2);
                            CoopAdminCommand.SendNetworkMessage("Banned " + data, source);
                        }
                        else
                        {
                            CoopAdminCommand.SendNetworkMessage("Invalid SteamId or Name, ban failed (data=" + data + ")", source);
                        }
                    }
                    break;
                }

                case 7:
                {
                    ulong num2;
                    if (ulong.TryParse(data, out num2))
                    {
                        CoopKick.UnBanPlayer(num2);
                        CoopAdminCommand.SendNetworkMessage("Unbanned " + data, source);
                    }
                    else if (CoopKick.UnBanPlayer(data))
                    {
                        CoopAdminCommand.SendNetworkMessage("Unbanned " + data, source);
                    }
                    else
                    {
                        CoopAdminCommand.SendNetworkMessage("Invalid SteamId or Name, unban failed (data=" + data + ")", source);
                    }
                    break;
                }

                case 8:
                    if (data == "on")
                    {
                        SteamDSConfig.TreeRegrowMode = true;
                        PlayerPreferences.SetLocalTreeRegrowth(SteamDSConfig.TreeRegrowMode);
                        CoopAdminCommand.SendNetworkMessage("TreeRegrowMode set to on", source);
                    }
                    else if (data == "off")
                    {
                        SteamDSConfig.TreeRegrowMode = false;
                        PlayerPreferences.SetLocalTreeRegrowth(SteamDSConfig.TreeRegrowMode);
                        CoopAdminCommand.SendNetworkMessage("TreeRegrowMode set to off", source);
                    }
                    else
                    {
                        CoopAdminCommand.SendNetworkMessage("Invalid parameter (data=" + data + ")", source);
                    }
                    break;

                case 9:
                    if (data == "on")
                    {
                        SteamDSConfig.AllowBuildingDestruction = true;
                        PlayerPreferences.SetLocalNoDestructionMode(!SteamDSConfig.AllowBuildingDestruction);
                        CoopAdminCommand.SendNetworkMessage("allowbuildingdestruction set to on", source);
                    }
                    else if (data == "off")
                    {
                        SteamDSConfig.AllowBuildingDestruction = false;
                        PlayerPreferences.SetLocalNoDestructionMode(!SteamDSConfig.AllowBuildingDestruction);
                        CoopAdminCommand.SendNetworkMessage("allowbuildingdestruction set to off", source);
                    }
                    else
                    {
                        CoopAdminCommand.SendNetworkMessage("Invalid parameter (data=" + data + ")", source);
                    }
                    break;

                case 10:
                    if (data == "on")
                    {
                        SteamDSConfig.AllowEnemiesCreative = true;
                        PlayerPreferences.SetLocalAllowEnemiesCreativeMode(SteamDSConfig.AllowEnemiesCreative);
                        CoopAdminCommand.SendNetworkMessage("AllowEnemiesCreative set to on", source);
                    }
                    else if (data == "off")
                    {
                        SteamDSConfig.AllowEnemiesCreative = false;
                        PlayerPreferences.SetLocalAllowEnemiesCreativeMode(SteamDSConfig.AllowEnemiesCreative);
                        CoopAdminCommand.SendNetworkMessage("AllowEnemiesCreative set to off", source);
                    }
                    else
                    {
                        CoopAdminCommand.SendNetworkMessage("Invalid parameter (data=" + data + ")", source);
                    }
                    break;

                case 11:
                    if (data == "on")
                    {
                        SteamDSConfig.AllowCheats = true;
                        PlayerPreferences.SetAllowCheatsMode(SteamDSConfig.AllowCheats);
                        CoopAdminCommand.SendNetworkMessage("allowcheats set to on", source);
                    }
                    else if (data == "off")
                    {
                        SteamDSConfig.AllowCheats = false;
                        PlayerPreferences.SetAllowCheatsMode(SteamDSConfig.AllowCheats);
                        CoopAdminCommand.SendNetworkMessage("allowcheats set to off", source);
                    }
                    else
                    {
                        CoopAdminCommand.SendNetworkMessage("Invalid parameter (data=" + data + ")", source);
                    }
                    break;
                }
            }
        }
    }
Esempio n. 4
0
    public static void KickPlayerByConnectionId(int connectionId, int duration = -1, string message = "HOST_KICKED_YOU")
    {
        BoltConnection connectionFromConnectionId = MpPlayerList.GetConnectionFromConnectionId(connectionId);

        CoopKick.KickPlayer(connectionFromConnectionId, null, duration, message);
    }