Exemple #1
0
            public void OnClientConnected(H3Server server, Peer peer)
            {
                byte count   = (byte)server._husks.Count;
                byte max     = server._config.PlayerLimit.Value;
                var  level   = new LevelChangeMessage(HarmonyState.CurrentLevel);
                var  players = new PlayerJoinMessage[count];

                {
                    var i = 0;
                    foreach (var husk in server._husks)
                    {
                        players[i++] = new PlayerJoinMessage(husk.Key, husk.Value.Latest);
                    }
                }

                peer.Send(new InitMessage(server._partyID, server.Secret, max, level, players));

                // Find first available player ID.
                byte id;

                for (id = 0; id < byte.MaxValue; ++id)
                {
                    if (!server._husks.ContainsKey(id))
                    {
                        break;
                    }
                }

                var peerHusk = new Husk(server._selfID == peer.ID);

                server._peerIDs.Add(peer, id);
                server._husks.Add(id, peerHusk);

                // Initialize just-joined puppet on other clients
                server.BroadcastExcept(peer, new PlayerJoinMessage(id, Timestamped <PlayerTransformsMessage> .Now(default)));
Exemple #2
0
        internal static void OnLevelChange(H3Server self, Peer peer, LevelChangeMessage message)
        {
            var husk = self[peer];

            if (!husk.IsSelf)             // self always has permissions
            {
                var config = self._config.Permissions;

                // scene reload
                if (HarmonyState.CurrentLevel == message.Name)
                {
                    if (!config.SceneReloading.Value)
                    {
                        return;
                    }
                }
                else                 // scene change
                {
                    if (!config.SceneChanging.Value)
                    {
                        return;
                    }
                }
            }

            self.Broadcast(message);
        }