private void AddPlayer(LANPlayerInfo lpInfo) { if (Players.Find(p => p.Name == lpInfo.Name) != null || Players.Count >= SGPlayers.Count || SGPlayers.Find(p => p.Name == lpInfo.Name) == null) { lpInfo.TcpClient.Close(); return; } if (Players.Count == 0) { lpInfo.Ready = true; } Players.Add(lpInfo); lpInfo.MessageReceived += LpInfo_MessageReceived; lpInfo.ConnectionLost += LpInfo_ConnectionLost; sndJoinSound.Play(); AddNotice(lpInfo.Name + " connected from " + lpInfo.IPAddress); lpInfo.StartReceiveLoop(); CopyPlayerDataToUI(); BroadcastOptions(); UpdateDiscordPresence(); }
private void BroadcastGame() { var sb = new ExtendedStringBuilder("GAME ", true); sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR; sb.Append(ProgramConstants.LAN_PROTOCOL_REVISION); sb.Append(ProgramConstants.GAME_VERSION); sb.Append(localGame); sb.Append(lblMapNameValue.Text); sb.Append(lblGameModeValue.Text); sb.Append(0); // LoadedGameID var sbPlayers = new StringBuilder(); SGPlayers.ForEach(p => sbPlayers.Append(p.Name + ",")); sbPlayers.Remove(sbPlayers.Length - 1, 1); sb.Append(sbPlayers.ToString()); sb.Append(Convert.ToInt32(started || Players.Count == SGPlayers.Count)); sb.Append(1); // IsLoadedGame GameBroadcast?.Invoke(this, new GameBroadcastEventArgs(sb.ToString())); }