private async void Ready()
        {
            IsReady       = true;
            IsPageEnabled = false;

            bool result;

            try
            {
                result = await lobbyServer.CreateLobby(CreateLobbySettings());

                ClientProxyManager.Instance.RegisterLobby(this);
            }
            catch (Exception)
            {
                MessageBox.Show("Connection lost.", "Hanksite", MessageBoxButton.OK);
                Application.Current.Shutdown();
                return;
            }

            IsPageEnabled = true;
            if (!result)
            {
                MessageBox.Show("The given lobby name is already used.", "Hanksite", MessageBoxButton.OK);
                IsReady = false;
                return;
            }

            ConnectedPlayers.Add(new Player()
            {
                Username = ClientProxyManager.Instance.UserName
            });
            NotifyPropertyChanged("ConnectedPlayers");
            NotifyPropertyChanged("IsLobbyFull");
        }
 public void AddPlayerToConnectedPlayers(string _playerID, GameObject _playerObject)
 {
     if (!ConnectedPlayers.ContainsKey(_playerID))
     {
         ConnectedPlayers.Add(_playerID, _playerObject);
         NumConnectedPlayers++;
     }
 }
Exemple #3
0
        private void OnUserConnected(string nick)
        {
            ConnectedPlayers.Add(new ListItem {
                Nick = nick
            });

            AvailablePlayers.Add(nick);
        }
Exemple #4
0
        public bool Register(string nick)
        {
            if (ConnectedPlayers.ContainsKey(nick))
            {
                return(false);
            }

            ConnectedPlayers.Add(nick, new PlayingClient(ClientCallback));

            return(true);
        }
Exemple #5
0
        /// <summary>
        /// Adds a connected player to the server
        /// </summary>
        /// <param name="connection">Connected player using a .NET Socket</param>
        public void AddConnection(Socket connection)
        {
            var player = (IPlayer)ScriptFactory.GetScript(MudDesigner.Engine.Properties.EngineSettings.Default.PlayerScript, null);

            player.Initialize(InitialConnectionState, connection, this);

            Thread userThread = new Thread(ReceiveDataThread);

            ConnectedPlayers.Add(player, userThread);

            userThread.Start(player);
        }
Exemple #6
0
            private static void Postfix(ref ZNet __instance, ref ZRpc rpc)
            {
                ZNetPeer peer = __instance.GetPeer(rpc);

                if (peer.m_characterID.IsNone() || !ZNet.instance.IsServer() || !__instance.IsConnected(peer.m_uid) || ConnectedPlayers.Contains(peer.m_characterID.userID))
                {
                    return;
                }
                ConnectedPlayers.Add(peer.m_characterID.userID);

                ValheimEventHandler.OnPlayerJoined(GetPlayerInfoFromPeer(peer));
            }
Exemple #7
0
    static void UpdateClientInfo(UdpClient client, uint pid, string name)
    {
        NetWerewolfPlayer player = ConnectedPlayers.FirstOrDefault(p => p.PlayerID == pid);

        if ((player == null) || (player.PlayerID != LocalPlayer.PlayerID))
        {
            player = new NetWerewolfPlayer(pid, name);
            if (ServerInstance == null)
            {
                ConnectedPlayers.Add(player);
            }
            UpdatePlayerList.Invoke(player.PlayerID, false);
        }
        else
        {
            player.Name = name;
        }
    }
Exemple #8
0
        internal IntegratedServer(int maxPlayers, LocalPlayer ply)
        {
            LocalPlayer = ply;

            if (maxPlayers <= 1)
            {
                IsSinglePlayer = true;
                MaxPlayers     = 1;
            }
            else
            {
                MaxPlayers = maxPlayers;
            }

            ConnectedPlayers.Add(LocalPlayer);

            var seed = "whats up guys, its scarce here".GetHashCode();

            World = new WorldServer(seed, ConnectedPlayers);
        }
Exemple #9
0
    static void ReceivePlayerList(UdpClient client, uint myPID, uint[] playerIDs, string[] playerNames)
    {
        LocalPlayer.PlayerID = myPID;

        for (int i = 0; i < playerIDs.Length; ++i)
        {
            bool isLocalPlayer          = LocalPlayer.PlayerID == playerIDs[i];
            NetWerewolfPlayer netPlayer = isLocalPlayer ? LocalPlayer : new NetWerewolfPlayer(playerIDs[i], playerNames[i]);

            if (isLocalPlayer)
            {
                LocalPlayer.Name = playerNames[i];
            }

            if (ServerInstance == null)
            {
                ConnectedPlayers.Add(netPlayer);
            }

            UpdatePlayerList.Invoke(netPlayer.PlayerID, false);
        }
    }
Exemple #10
0
        Player AddPlayer(IWebSocketConnection socket)
        {
            if (ConnectedPlayers == null)
            {
                ConnectedPlayers = new List <Player>();
            }

            Player player = GetPlayerFromSocket(socket);

            if (player == null)
            {
                player         = new Player("N/A", socket, SettingsLoader.Values);
                player.Data.ID = Guid.NewGuid().ToString();

                ConnectedPlayers.Add(player);
            }
            else
            {
                Logger.Warn(this, "Player {0} already exists...", player.Data.Name);
            }

            return(player);
        }
Exemple #11
0
 private void PlayerConnectCallback(CSteamID id)
 {
     ConnectedPlayers.Add(id.m_SteamID, new UPlayer(UnturnedPlayer.FromCSteamID(id)));
 }
Exemple #12
0
        protected override void Load()
        {
            try {
                var stopwatch = Stopwatch.StartNew();

                Instance = this;

                R.Plugins.OnPluginsLoaded += OverrideCommands;

                TaskExecutor = new EssentialsTaskExecutor();

                //SteamGameServer.SetKeyValue("essversion", PLUGIN_VERSION);

                Logger = new ConsoleLogger("[uEssentials] ");

                _consoleTraceListener = new EssentialsConsoleTraceListener();
                Debug.Listeners.Add(_consoleTraceListener);

                Provider.onServerDisconnected += PlayerDisconnectCallback;
                Provider.onServerConnected    += PlayerConnectCallback;

                Logger.LogInfo("Enabling uEssentials...");

                new [] {
                    "Plugin version: ~white~" + PLUGIN_VERSION + BUILD_INFO,
                    "Recommended Rocket version: ~white~" + ROCKET_VERSION,
                    "Recommended Unturned version: ~white~" + UNTURNED_VERSION,
                    "Author: ~white~leonardosnt",
                    "Wiki: ~white~uessentials.github.io",
                }.ForEach(text => Logger.LogInfo(text, true));

                if (Provider.clients.Count > 0)
                {
                    Provider.clients.ForEach(p => {
                        ConnectedPlayers.Add(p.playerID.steamID.m_SteamID,
                                             new UPlayer(UnturnedPlayer.FromSteamPlayer(p)));
                    });
                }

                _folder            = Rocket.Core.Environment.PluginsDirectory + "/uEssentials/";
                _translationFolder = Folder + "translations/";
                _dataFolder        = Folder + "data/";
                _modulesFolder     = Folder + "modules/";

                CommandOptions = new CommandOptions();
                //Updater = new GithubUpdater();
                EventManager   = new EventManager();
                CommandManager = new CommandManager();
                ModuleManager  = new ModuleManager();
                HookManager    = new HookManager();

                WebResources = new WebResources();
                Config       = new EssConfig();

                var webResourcesPath = Path.Combine(Folder, WebResources.FileName);
                var configPath       = Path.Combine(Folder, Config.FileName);

                WebResources.Load(webResourcesPath);

                // Sync web config with local config.json
                if (WebResources.Loaded.ContainsKey("Config"))
                {
                    File.WriteAllText(configPath, WebResources.Loaded["Config"]);
                }

                Config.Load(configPath);
                CommandOptions.Load(Path.Combine(Folder, CommandOptions.FileName));
                EssLang.Load();

                EventManager.RegisterAll(GetType().Assembly);

                // Register all commands from namespace Essentials.Commands
                CommandManager.RegisterAll("Essentials.Commands");

                HookManager.RegisterAll();
                HookManager.LoadAll();

                // Load after EventManager because we relies on it inside this routine.
                ConfigPostLoad();

                LoadNativeModules();

                Logger.LogInfo("Loading modules...");
                ModuleManager.LoadAll(ModulesFolder);
                Logger.LogInfo($"Loaded {ModuleManager.RunningModules.Count(t => !(t is NativeModule))} modules");

                // We log it here because the modules being loaded above can
                // register commands.
                Logger.LogInfo($"Loaded {CommandManager.Commands.Count()} commands");

#if EXPERIMENTAL
                Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, IT CAN BE BUGGY.");
                Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, IT CAN BE BUGGY.");
#endif

                // Delete useless files generated by Rocket
                Task.Create()
                .Id("Delete Xml Files")
                .Delay(TimeSpan.FromSeconds(1))
                .Async()
                .Action(() => {
                    File.Delete($"{Folder}uEssentials.en.translation.xml");
                    File.Delete($"{Folder}uEssentials.configuration.xml");
                })
                .Submit();

                // If _wasLoadedBefore, then it means that uEssentials is
                // being reloaded, and it also means that R.Plugins.OnPluginsLoaded will not be called,
                // consequently OverrideCommands will not be called too
                // so we need to call it here.
                if (_wasLoadedBefore)
                {
                    OverrideCommands();
                }

                _wasLoadedBefore = true;
                CommandWindow.input.onInputText += ReloadCallback;
                Logger.LogInfo($"Enabled ({stopwatch.ElapsedMilliseconds} ms)");
            } catch (Exception e) {
                string[] messages =
                {
                    "An error occurred while enabling uEssentials.",
                    "If this error is not related with wrong configuration, please report",
                    "it here https://github.com/uEssentials/uEssentials/issues",
                    "Error: " + e
                };

                if (Logger == null)
                {
                    Console.BackgroundColor = ConsoleColor.Red;
                    messages.ForEach(Console.WriteLine);
                    Console.BackgroundColor = ConsoleColor.White;
                }
                else
                {
                    messages.ForEach(m => Logger.LogError(m));
                }
            }

#if !DEV
            Analytics.SendEvent($"ServerInit");
#endif

#if DEV
            //Console.Title = "Unturned Server";
//#else
            //CheckUpdates();
#endif
        }
Exemple #13
0
        private void newLogin()
        {
            //When a player logs in, we expect that he sends his character info to us.
            //Normally he would only send his username and password but because we aren't using a database model
            //We'll just create the users character in their own client. Maybe database example next time
            //FYI: The connecting player can manually specify the zone he wants to connect to, easily changed by just setting the property though

            //Create new instance of player then read all the properties the client has sent into this class
            Character newlyConnectedPlayer = new Character();

            inc.ReadAllProperties(newlyConnectedPlayer);

            //If the player that is trying to connects' name already exists in our active player list
            //We will refuse his connection. This can be handy, if you want to allow only one character (obviously) or one
            //connection per IP Address, easy to modify
            if (ConnectedPlayers.FirstOrDefault(f => f.Name == newlyConnectedPlayer.Name) != null)
            {
                inc.SenderConnection.Deny("You're already connected");
                Write("Refused player with name " + newlyConnectedPlayer.Name + " because he was already connected.."); // LET IT BE KNOWN!
                return;
            }

            //We give our player a connection property so we can keep connection info about him, like IP Address/ping, etc!
            newlyConnectedPlayer.Connection = inc.SenderConnection;

            //Let it be known that this player has connected to our wonderful game
            Write(newlyConnectedPlayer.Name + " has connected!");

            //Approve this fine gentleman into our secret society
            inc.SenderConnection.Approve();

            //Add this fine lad to the list of connected players
            ConnectedPlayers.Add(newlyConnectedPlayer);


            //Now it gets a little more interesting!
            //*~*~*~*~* (SPARKLES TO MAKE IT MORE MAGICAL!) *~*~*~*~*

            //Worldstate (Can specify a name yourself) messages send the current zone state to players

            NetOutgoingMessage outmsg = Server.CreateMessage(); //We create a new message

            outmsg.Write((byte)PacketTypes.WORLDSTATE);         // Of type WORLDSTATE

            //Get the amount of players the zone the new player is in
            outmsg.Write(ConnectedPlayers.Where(f => f.CurrentZone == newlyConnectedPlayer.CurrentZone).Count()); //notice 'Count'

            //For each player in this players' zone, send him the data of the players. (The players' client will process this info and draw them on his screen)
            foreach (Character ch in ConnectedPlayers.Where(x => x.CurrentZone == newlyConnectedPlayer.CurrentZone))
            {
                outmsg.WriteAllProperties(ch);
            }
            Server.SendMessage(outmsg, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0); // Send the message, reliably and ordered

            // LET IT BE KNOWN!
            Write(String.Format("{0} : {1}  - has connected to the server and is in {2}", newlyConnectedPlayer.Name,
                                newlyConnectedPlayer.Connection.RemoteEndpoint.Address,
                                newlyConnectedPlayer.CurrentZone));

            //Update our UI
            updateList();
        }
 public static void ClientConnectedEventHandler(UdpClient client)
 {
     ConnectedPlayers.Add(new NetWerewolfPlayer(client));
     client.Send(0); // CreateRoleHashesAndVerify()
 }