public NetClient(string connection, ushort port, ILogger logger = null, string password = null, bool connectOnInit = true) { if (logger != null) { Logger = new ModuleLogger(logger, "CLIENT"); } else { Logger = new NullLogger(); } MessageProcessor = new ClientNetworkProcessor(this); GameInstance = new NetworkedGame(null); Chat = new Chat.ChatClient(this); Host = connection; Port = port; Password = password; NetworkClient = new Lidgren.Network.NetClient( new Lidgren.Network.NetPeerConfiguration("MPTANKS") { ConnectionTimeout = 15, AutoFlushSendQueue = false }); SetupNetwork(); if (connectOnInit) { Connect(); } }
public void InitOnlineMatch(Lidgren.Network.NetClient client, MatchState matchState) { //Create existing clients foreach (var clientInfo in matchState.Clients) { clients.Add(new MatchClient(clientInfo.Guid, clientInfo.Name)); } //Create existing players foreach (var playerInfo in matchState.Players) { MatchPlayer p = new MatchPlayer(playerInfo.ClientGuid, playerInfo.CtrlType, playerInfo.CharacterId); p.ReadyToRace = playerInfo.ReadyToRace; players.Add(p); if (inLobby) { SpawnLobbyBall(p); } } //Set settings currentSettings = matchState.Settings; //Set auto start timer //TODO Get and apply travel time autoStartTimerOn = matchState.CurAutoStartTime != 0; autoStartTimer = matchState.CurAutoStartTime; //Create messenger OnlineMatchMessenger messenger = new OnlineMatchMessenger(client); this.messenger = messenger; messenger.Disconnected += (sender, e) => { QuitMatch(e.Reason); }; messenger.OnPlayerMovement += OnlinePlayerMovement; //Create chat activeChat = Instantiate(chatPrefab); activeChat.MessageSent += LocalChatMessageSent; //Enter the lobby or stage if (matchState.InRace) { joiningRaceInProgress = true; GoToStage(); } else { //showSettingsOnLobbyLoad = true; GoToLobby(); } }