public override NCError OnHostServer( string identifier, int port, NetworkLobbyType lobbyType, int maxConnections) { foreach (Lobby activeLobby in this._activeLobbies) { Steam.LeaveLobby(activeLobby); DevConsole.Log(DCSection.Steam, "|DGYELLOW|Leaving lobby to host new lobby."); } this._lobby = (Lobby)null; if (this._lobby != null) { return(new NCError("Server is already started...", NCErrorType.Error)); } this.HookUpDelegates(); this._initializedSettings = false; this._lobby = Steam.CreateLobby((SteamLobbyType)lobbyType, maxConnections); this._activeLobbies.Add(this._lobby); if (this._lobby == null) { return(new NCError("|DGORANGE|STEAM |DGRED|Steam is not running.", NCErrorType.Error)); } this._userChange = new Lobby.UserStatusChangeDelegate(this.OnUserStatusChange); this._lobby.UserStatusChange += this._userChange; this._serverIdentifier = identifier; this._port = port; this.StartServerThread(); return(new NCError("|DGORANGE|STEAM |DGYELLOW|Attempting to create server lobby...", NCErrorType.Message)); }
public override NCError OnHostServer( string identifier, int port, NetworkLobbyType lobbyType, int maxConnections) { if (this._socket != null) { return(new NCError("server is already started...", NCErrorType.Error)); } this._serverIdentifier = identifier; this._socket = new UdpClient(); this._socket.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); this._socket.Client.Bind((EndPoint) new IPEndPoint(IPAddress.Any, port)); this._socket.AllowNatTraversal(true); this._port = port; this._isAServer = true; this.StartServerThread(); this.StartPacketThread(); return(new NCError("server started on port " + (object)port + ".", NCErrorType.Success)); }
public static void Host(int maxPlayers, NetworkLobbyType lobbyType) { if (_core.status != DuckNetStatus.Disconnected) { return; } // DevConsole.Log(DCSection.DuckNet, "|LIME|Hosting new server. ", -1); // Rubbish fix for Update calling host with 4 max players. Need better way if (maxPlayers == 4 && lobbyType == NetworkLobbyType.FriendsOnly) { maxPlayers = 8; } DuckNetwork.Reset(); foreach (Profile universalProfile in Profiles.universalProfileList) { universalProfile.team = (Team)null; } _core.error = (DuckNetErrorInfo)null; TeamSelect2.DefaultSettings(); Network.HostServer(lobbyType, maxPlayers, "duckGameServer", 1337); DuckNetwork.localConnection.AttemptConnection(); foreach (Profile profile in DuckNetwork.profiles) { profile.slotType = lobbyType != NetworkLobbyType.Private ? (lobbyType != NetworkLobbyType.FriendsOnly ? SlotType.Open : SlotType.Friend) : SlotType.Invite; if ((int)profile.networkIndex >= maxPlayers) { profile.slotType = SlotType.Closed; } } int num = 1; _core.localDuckIndex = -1; foreach (MatchmakingPlayer matchmakingProfile in UIMatchmakingBox.matchmakingProfiles) { string name = Network.activeNetwork.core.GetLocalName(); if (num > 1) { name = name + "(" + num.ToString() + ")"; } if (_core.localDuckIndex == -1) { _core.localDuckIndex = (int)matchmakingProfile.duckIndex; _core.hostDuckIndex = (int)matchmakingProfile.duckIndex; } Profile profile = (Profile)createProfile.Invoke(null, new object[] { _core.localConnection, name, (int)matchmakingProfile.duckIndex, matchmakingProfile.inputProfile, false, false, false }); if (num > 1) { profile.slotType = SlotType.Local; } profile.networkStatus = DuckNetStatus.Connected; if (matchmakingProfile.team != null) { if (matchmakingProfile.team.customData != null) { profile.team = Teams.all[(int)matchmakingProfile.duckIndex]; Team.MapFacade(profile.steamID, matchmakingProfile.team); } else { profile.team = matchmakingProfile.team; } } ++num; } _core.localConnection.isHost = true; _core.status = DuckNetStatus.Connecting; }