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); }
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); }
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)); } } }
public void KickPlayer(BzzrPlayer player) { _ = _socket.EmitAsync("player.kick", player.UserID); }
public void UnlockPlayer(BzzrPlayer player) { _ = _socket.EmitAsync("buzzer.player.unlock", player.UserID); }