示例#1
0
 public Buzz(BzzrPlayer player, double serverTime, double localTime)
 {
     Player      = player;
     ServerTime  = TimeSpan.FromMilliseconds(serverTime);
     LocalTime   = TimeSpan.FromMilliseconds(localTime);
     AverageTime = TimeSpan.FromMilliseconds((serverTime + localTime) * 0.5);
 }
示例#2
0
        public void UpdatePlayer(BzzrPlayer player, string newName = null, string newColorName = null)
        {
            JObject obj = new JObject(
                new JProperty("userId", player.UserID),
                new JProperty("name", newName != null ? newName : player.Name)
                );

            if (newColorName != null || player.ColorName != null)
            {
                obj.Add("color", newColorName != null ? newColorName : player.ColorName);
            }

            _ = _socket.EmitAsync("player.update", obj);
        }
示例#3
0
        private void OnPlayersUpdate(SocketIOResponse response)
        {
            List <BzzrPlayer> oldPlayers = new List <BzzrPlayer>(Players.Values);

            foreach (JObject playerData in response.GetValue() as JArray)
            {
                string userID = (string)playerData["userId"];
                if (Players.TryGetValue(userID, out BzzrPlayer player))
                {
                    bool wasConnected = player.Connected;
                    player.Update(playerData);

                    if (player.Connected != wasConnected)
                    {
                        if (player.Connected)
                        {
                            Log($"Player <b>{player.Name}</b> reconnected.");
                            DoUnityAction(() => OnPlayerReconnected.Invoke(player));
                        }
                        else
                        {
                            Log($"Player <b>{player.Name}</b> disconnected.");
                            DoUnityAction(() => OnPlayerDisconnected.Invoke(player));
                        }
                    }

                    oldPlayers.Remove(player);
                }
                else
                {
                    BzzrPlayer newPlayer = new BzzrPlayer(playerData);
                    Players[userID] = newPlayer;

                    Log($"Player <b>{newPlayer.Name}</b> connected.");
                    DoUnityAction(() => OnPlayerJoined.Invoke(newPlayer));
                }
            }

            foreach (BzzrPlayer oldPlayer in oldPlayers)
            {
                Log($"<b>{oldPlayer.Name}</b> has been kicked.");
                if (Players.TryRemove(oldPlayer.UserID, out _))
                {
                    DoUnityAction(() => OnPlayerKicked.Invoke(oldPlayer));
                }
            }
        }
示例#4
0
 public void KickPlayer(BzzrPlayer player)
 {
     _ = _socket.EmitAsync("player.kick", player.UserID);
 }
示例#5
0
 public void UnlockPlayer(BzzrPlayer player)
 {
     _ = _socket.EmitAsync("buzzer.player.unlock", player.UserID);
 }