public override void OnApplicationStart() { // Setup MonoBehaviors ClassInjector.RegisterTypeInIl2Cpp <ServerSyncedObject>(); ClassInjector.RegisterTypeInIl2Cpp <IDHolder>(); // Register Prefs ModPrefs.RegisterCategory("MPMod", "Multiplayer Settings"); ModPrefs.RegisterPrefString("MPMod", "HostSteamID", "0"); ModPrefs.RegisterPrefBool("MPMod", "ForceLargePlayspace", true); // Start Server Stuff SteamClient.Init(448280); // MelonModLogger.LogWarning("ALPHA TESTING BUILD"); MelonModLogger.Log($"Multiplayer initialising with protocol version {PROTOCOL_VERSION}."); SteamNetworking.AllowP2PPacketRelay(true); client = new Client(); server = new Server(); PlayerRep.LoadPlayer(); // Setup Discord Presence RichPresence.Initialise(736050983335100436); client.SetupRP(); MelonModLogger.Log("MPMod Loaded"); }
public override void ServerStart() { if (!SteamManager.Initialized) { Debug.LogError("SteamWorks not initialized. Server could not be started."); return; } FetchSteamID(); if (ClientActive()) { Debug.LogError("Transport already running as client!"); return; } if (!ServerActive()) { Debug.Log("Starting server."); SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay); server = Server.CreateServer(this, NetworkManager.singleton.maxConnections); activeNode = server; } else { Debug.LogError("Server already started!"); } }
private void OnSteamOnline() { Trace.TraceInformation("Steam online"); lobbyJoinRequestCallback = new Callback <GameLobbyJoinRequested_t>(t => { JoinFriendRequest(t.m_steamIDFriend.m_SteamID); }); overlayActivatedCallback = new Callback <GameOverlayActivated_t>(t => { OverlayActivated(t.m_bActive != 0); }); newConnectionCallback = Callback <P2PSessionRequest_t> .Create(t => SteamNetworking.AcceptP2PSessionWithUser(t.m_steamIDRemote)); MySteamNameSanitized = Utils.StripInvalidLobbyNameChars(GetMyName()); var ev = new EventWaitHandle(false, EventResetMode.ManualReset); AuthToken = GetClientAuthTokenHex(); CreateLobbyAsync((lobbyID) => { if (lobbyID != null) { LobbyID = lobbyID; } ev.Set(); }); SteamNetworking.AllowP2PPacketRelay(true); Friends = GetFriends(); ev.WaitOne(2000); SteamOnline?.Invoke(); }
public override void ServerStart() { if (!SteamClient.IsValid) { Debug.LogError("SteamWorks not initialized. Server could not be started."); return; } FetchSteamID(); if (ClientActive()) { Debug.LogError("Transport already running as client!"); return; } if (!ServerActive()) { if (UseNextGenSteamNetworking) { Debug.Log($"Starting server [SteamSockets]."); server = NextServer.CreateServer(this, NetworkManager.singleton.maxConnections); } else { Debug.Log($"Starting server [DEPRECATED SteamNetworking]. Relay enabled: {AllowSteamRelay}"); SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay); server = LegacyServer.CreateServer(this, NetworkManager.singleton.maxConnections); } } else { Debug.LogError("Server already started!"); } }
public override void ClientConnect(string address) { if (!SteamManager.Initialized) { Debug.LogError("SteamWorks not initialized. Client could not be started."); OnClientDisconnected.Invoke(); return; } FetchSteamID(); if (ServerActive()) { Debug.LogError("Transport already running as server!"); return; } if (!ClientActive() || client.Error) { Debug.Log($"Starting client, target address {address}."); SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay); client = Client.CreateClient(this, address); activeNode = client; } else { Debug.LogError("Client already running!"); } }
private void OnLobbyEntered(LobbyEnter_t result, bool failure) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) WeGameHelper.WriteDebugString(" OnLobbyEntered"); SteamNetworking.AllowP2PPacketRelay(true); SendAuthTicket(_lobby.Owner); int num = 0; P2PSessionState_t val = default(P2PSessionState_t); while (SteamNetworking.GetP2PSessionState(_lobby.Owner, ref val) && val.m_bConnectionActive != 1) { switch (val.m_eP2PSessionError) { case 2: ClearAuthTicket(); return; case 1: ClearAuthTicket(); return; case 3: ClearAuthTicket(); return; case 5: ClearAuthTicket(); return; case 4: if (++num > 5) { ClearAuthTicket(); return; } SteamNetworking.CloseP2PSessionWithUser(_lobby.Owner); SendAuthTicket(_lobby.Owner); break; } } _connectionStateMap[_lobby.Owner] = ConnectionState.Connected; SteamFriends.SetPlayedWith(_lobby.Owner); SteamFriends.SetRichPresence("status", Language.GetTextValue("Social.StatusInGame")); Main.clrInput(); Netplay.ServerPassword = ""; Main.GetInputText(""); Main.autoPass = false; Main.netMode = 1; Netplay.OnConnectedToSocialServer(new SocialSocket(new SteamAddress(_lobby.Owner))); }
private void OnLobbyEntered(LobbyEnter_t result, bool failure) { SteamNetworking.AllowP2PPacketRelay(true); this.SendAuthTicket(this._lobby.Owner); var num = 0; P2PSessionState_t p2PsessionStateT; while (SteamNetworking.GetP2PSessionState(this._lobby.Owner, out p2PsessionStateT) && p2PsessionStateT.m_bConnectionActive != 1) { switch ((byte)p2PsessionStateT.m_eP2PSessionError) { case 1: this.ClearAuthTicket(); return; case 2: this.ClearAuthTicket(); return; case 3: this.ClearAuthTicket(); return; case 4: if (++num > 5) { this.ClearAuthTicket(); return; } SteamNetworking.CloseP2PSessionWithUser(this._lobby.Owner); this.SendAuthTicket(this._lobby.Owner); continue; case 5: this.ClearAuthTicket(); return; default: continue; } } this._connectionStateMap[this._lobby.Owner] = NetSocialModule.ConnectionState.Connected; SteamFriends.SetPlayedWith(this._lobby.Owner); SteamFriends.SetRichPresence("status", Language.GetTextValue("Social.StatusInGame")); Main.clrInput(); Netplay.ServerPassword = ""; Main.GetInputText(""); Main.autoPass = false; Main.netMode = 1; Netplay.OnConnectedToSocialServer( (ISocket) new SocialSocket((RemoteAddress) new SteamAddress(this._lobby.Owner))); }
public void ConnectWithSteamId(ulong friendSteamId, PlayerInformation playerInfos, string serverPassword = "") { _friendSteamId = new CSteamID(friendSteamId); SteamNetworking.AllowP2PPacketRelay(true); SendAuthTicket(); P2PSessionState_t state; while (SteamNetworking.GetP2PSessionState(_friendSteamId.Value, out state) && state.m_bConnectionActive != 1) { } InitPlayerInfos(playerInfos, serverPassword); }
private void OnLobbyEntered(LobbyEnter_t result, bool failure) { SteamNetworking.AllowP2PPacketRelay(true); SendAuthTicket(_lobby.Owner); int num = 0; P2PSessionState_t pConnectionState; while (SteamNetworking.GetP2PSessionState(_lobby.Owner, out pConnectionState) && pConnectionState.m_bConnectionActive != 1) { switch (pConnectionState.m_eP2PSessionError) { case 2: ClearAuthTicket(); return; case 1: ClearAuthTicket(); return; case 3: ClearAuthTicket(); return; case 5: ClearAuthTicket(); return; case 4: if (++num > 5) { ClearAuthTicket(); return; } SteamNetworking.CloseP2PSessionWithUser(_lobby.Owner); SendAuthTicket(_lobby.Owner); break; } } _connectionStateMap[_lobby.Owner] = ConnectionState.Connected; SteamFriends.SetPlayedWith(_lobby.Owner); SteamFriends.SetRichPresence("status", "Playing online."); Main.clrInput(); Netplay.ServerPassword = ""; Main.GetInputText(""); Main.autoPass = false; Main.netMode = 1; Netplay.OnConnectedToSocialServer(new SocialSocket(new SteamAddress(_lobby.Owner))); }
public override void ServerStart() { try { #if UNITY_SERVER SteamGameServerNetworkingUtils.InitRelayNetworkAccess(); #else SteamNetworkingUtils.InitRelayNetworkAccess(); #endif InitRelayNetworkAccess(); if (ClientActive()) { Debug.LogError("Transport already running as client!"); return; } if (!ServerActive()) { if (UseNextGenSteamNetworking) { Debug.Log($"Starting server [SteamSockets]."); server = NextServer.CreateServer(this, NetworkManager.singleton.maxConnections); } else { Debug.Log($"Starting server [DEPRECATED SteamNetworking]. Relay enabled: {AllowSteamRelay}"); #if UNITY_SERVER SteamGameServerNetworking.AllowP2PPacketRelay(AllowSteamRelay); #else SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay); #endif server = LegacyServer.CreateServer(this, NetworkManager.singleton.maxConnections); } } else { Debug.LogError("Server already started!"); } } catch (Exception ex) { Debug.LogException(ex); return; } }
public override void ClientConnect(string address) { try { #if UNITY_SERVER SteamGameServerNetworkingUtils.InitRelayNetworkAccess(); #else SteamNetworkingUtils.InitRelayNetworkAccess(); #endif InitRelayNetworkAccess(); if (ServerActive()) { Debug.LogError("Transport already running as server!"); return; } if (!ClientActive() || client.Error) { if (UseNextGenSteamNetworking) { Debug.Log($"Starting client [SteamSockets], target address {address}."); client = NextClient.CreateClient(this, address); } else { Debug.Log($"Starting client [DEPRECATED SteamNetworking], target address {address}. Relay enabled: {AllowSteamRelay}"); SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay); client = LegacyClient.CreateClient(this, address); } } else { Debug.LogError("Client already running!"); } } catch (Exception ex) { Debug.LogError("Exception: " + ex.Message + ". Client could not be started."); OnClientDisconnected.Invoke(); } }
public override void ClientConnect(string address) { if (!SteamClient.IsValid) { Debug.LogError("SteamWorks not initialized. Client could not be started."); OnClientDisconnected.Invoke(); return; } if (address == SteamUserID.ToString()) { Debug.Log("You can't connect to yourself."); return; } FetchSteamID(); if (ServerActive()) { Debug.LogError("Transport already running as server!"); return; } if (!ClientActive() || client.Error) { if (UseNextGenSteamNetworking) { Debug.Log($"Starting client [SteamSockets], target address {address}."); client = NextClient.CreateClient(this, address); } else { Debug.Log($"Starting client [DEPRECATED SteamNetworking], target address {address}. Relay enabled: {AllowSteamRelay}"); SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay); client = LegacyClient.CreateClient(this, address); } } else { Debug.LogError("Client already running!"); } }
public override async Task Initialize(NetworkInterfaceConfiguration config) { ValidateSteamInitalized(); await base.Initialize(config); Debug.Log($"[Steam] Steam User ID: {SteamUser.GetSteamID()}"); callbackP2PSesssionRequest = Callback <P2PSessionRequest_t> .Create(OnP2PSessionRequest); callbackP2PConnectFail = Callback <P2PSessionConnectFail_t> .Create(OnP2PSessionConnectFail); callbackLobbyChatUpdate = Callback <LobbyChatUpdate_t> .Create(OnLobbyChatUpdate); // Allow use of Steam relay servers SteamNetworking.AllowP2PPacketRelay(true); if (config.Type != NetworkInterfaceType.Server) { return; } var type = config.ServerSteamLobbyType; var size = config.ServerSteamLobbyMaxSize; Debug.Log($"[Steam] Creating lobby"); var result = await SteamMatchmaking.CreateLobby(type, size).ToTask <LobbyCreated_t>(); Debug.Log($"[Steam] Creating lobby"); if (SteamUtility.IsError(result.m_eResult)) { throw SteamUtility.CreateError(result.m_eResult); } var lobbyEnter = await SteamUtility.WaitFor <LobbyEnter_t>(); currentLobbyId = new CSteamID(lobbyEnter.m_ulSteamIDLobby); Debug.Log($"[Steam] Created server lobby ID: {currentLobbyId}"); SetLobbyData(currentLobbyId); }
public void RenderOnGUI() { GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height)); GUILayout.Label("Variables:"); GUILayout.Label("m_RemoteSteamId: " + m_RemoteSteamId); GUILayout.EndArea(); if (!m_RemoteSteamId.IsValid()) { GUILayout.Label("Please fill m_RemoteSteamId with a valid 64bit SteamId to use SteamNetworkingTest."); GUILayout.Label("Alternatively it will be filled automatically when a session request is recieved."); return; } // Session-less connection functions if (GUILayout.Button("SendP2PPacket(m_RemoteSteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable)")) { byte[] bytes = new byte[4]; using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes)) using (System.IO.BinaryWriter b = new System.IO.BinaryWriter(ms)) { b.Write((uint)MsgType.Ping); } bool ret = SteamNetworking.SendP2PPacket(m_RemoteSteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable); print("SteamNetworking.SendP2PPacket(" + m_RemoteSteamId + ", bytes, " + bytes.Length + ", EP2PSend.k_EP2PSendReliable) - " + ret); } { uint MsgSize; bool ret = SteamNetworking.IsP2PPacketAvailable(out MsgSize); GUILayout.Label("IsP2PPacketAvailable(out MsgSize) : " + ret + " -- " + MsgSize); GUI.enabled = ret; if (GUILayout.Button("ReadP2PPacket(bytes, MsgSize, out newMsgSize, out SteamIdRemote)")) { byte[] bytes = new byte[MsgSize]; uint newMsgSize; CSteamID SteamIdRemote; ret = SteamNetworking.ReadP2PPacket(bytes, MsgSize, out newMsgSize, out SteamIdRemote); using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes)) using (System.IO.BinaryReader b = new System.IO.BinaryReader(ms)) { MsgType msgtype = (MsgType)b.ReadUInt32(); // switch statement here depending on the msgtype print("SteamNetworking.ReadP2PPacket(bytes, " + MsgSize + ", out newMsgSize, out SteamIdRemote) - " + ret + " -- " + newMsgSize + " -- " + SteamIdRemote + " -- " + msgtype); } } GUI.enabled = true; } // bool AcceptP2PSessionWithUser(CSteamID steamIDRemote) // Only called from within P2PSessionRequest Callback! if (GUILayout.Button("CloseP2PSessionWithUser(m_RemoteSteamId)")) { bool ret = SteamNetworking.CloseP2PSessionWithUser(m_RemoteSteamId); print("SteamNetworking.CloseP2PSessionWithUser(" + m_RemoteSteamId + ") - " + ret); } if (GUILayout.Button("CloseP2PChannelWithUser(m_RemoteSteamId, 0)")) { bool ret = SteamNetworking.CloseP2PChannelWithUser(m_RemoteSteamId, 0); print("SteamNetworking.CloseP2PChannelWithUser(" + m_RemoteSteamId + ", 0) - " + ret); } { P2PSessionState_t ConnectionState; bool ret = SteamNetworking.GetP2PSessionState(m_RemoteSteamId, out ConnectionState); GUILayout.Label("GetP2PSessionState(m_RemoteSteamId, out ConnectionState) : " + ret + " -- " + ConnectionState.m_bConnectionActive + " -- " + ConnectionState.m_bConnecting + " -- " + ConnectionState.m_eP2PSessionError + " -- " + ConnectionState.m_bUsingRelay + " -- " + ConnectionState.m_nBytesQueuedForSend + " -- " + ConnectionState.m_nPacketsQueuedForSend + " -- " + ConnectionState.m_nRemoteIP + " -- " + ConnectionState.m_nRemotePort); } if (GUILayout.Button("AllowP2PPacketRelay(true)")) { bool ret = SteamNetworking.AllowP2PPacketRelay(true); print("SteamNetworking.AllowP2PPacketRelay(true) - " + ret); } // LISTEN / CONNECT style interface functions }
public SteamTransportLayer() { // Allows for the networking to fallback onto steam's servers SteamNetworking.AllowP2PPacketRelay(true); msgThread = new Thread(SendMessagesThread); }
public void RenderOnGUI() { GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height)); GUILayout.Label("Variables:"); GUILayout.Label("m_RemoteSteamId: " + m_RemoteSteamId); GUILayout.EndArea(); GUILayout.BeginVertical("box"); m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, GUILayout.Width(Screen.width - 215), GUILayout.Height(Screen.height - 33)); if (!m_RemoteSteamId.IsValid()) { GUILayout.Label("Please fill m_RemoteSteamId with a valid 64bit SteamId to use SteamNetworkingTest."); GUILayout.Label("Alternatively it will be filled automatically when a session request is recieved."); GUILayout.EndScrollView(); GUILayout.EndVertical(); return; } // Session-less connection functions if (GUILayout.Button("SendP2PPacket(m_RemoteSteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable)")) { byte[] bytes = new byte[4]; using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes)) using (System.IO.BinaryWriter b = new System.IO.BinaryWriter(ms)) { b.Write((uint)MsgType.Ping); } bool ret = SteamNetworking.SendP2PPacket(m_RemoteSteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable); print("SteamNetworking.SendP2PPacket(" + m_RemoteSteamId + ", " + bytes + ", " + (uint)bytes.Length + ", " + EP2PSend.k_EP2PSendReliable + ") : " + ret); } { uint MsgSize; bool ret = SteamNetworking.IsP2PPacketAvailable(out MsgSize); GUILayout.Label("IsP2PPacketAvailable(out MsgSize) : " + ret + " -- " + MsgSize); GUI.enabled = ret; if (GUILayout.Button("ReadP2PPacket(bytes, MsgSize, out newMsgSize, out SteamIdRemote)")) { byte[] bytes = new byte[MsgSize]; uint newMsgSize; CSteamID SteamIdRemote; ret = SteamNetworking.ReadP2PPacket(bytes, MsgSize, out newMsgSize, out SteamIdRemote); using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes)) using (System.IO.BinaryReader b = new System.IO.BinaryReader(ms)) { MsgType msgtype = (MsgType)b.ReadUInt32(); // switch statement here depending on the msgtype print("SteamNetworking.ReadP2PPacket(bytes, " + MsgSize + ", out newMsgSize, out SteamIdRemote) - " + ret + " -- " + newMsgSize + " -- " + SteamIdRemote + " -- " + msgtype); } } GUI.enabled = true; } //SteamNetworking.AcceptP2PSessionWithUser() // Only called from within P2PSessionRequest Callback! if (GUILayout.Button("CloseP2PSessionWithUser(m_RemoteSteamId)")) { bool ret = SteamNetworking.CloseP2PSessionWithUser(m_RemoteSteamId); print("SteamNetworking.CloseP2PSessionWithUser(" + m_RemoteSteamId + ") : " + ret); } if (GUILayout.Button("CloseP2PChannelWithUser(m_RemoteSteamId, 0)")) { bool ret = SteamNetworking.CloseP2PChannelWithUser(m_RemoteSteamId, 0); print("SteamNetworking.CloseP2PChannelWithUser(" + m_RemoteSteamId + ", " + 0 + ") : " + ret); } { P2PSessionState_t ConnectionState; bool ret = SteamNetworking.GetP2PSessionState(m_RemoteSteamId, out ConnectionState); GUILayout.Label("GetP2PSessionState(m_RemoteSteamId, out ConnectionState) : " + ret + " -- " + ConnectionState); } if (GUILayout.Button("AllowP2PPacketRelay(true)")) { bool ret = SteamNetworking.AllowP2PPacketRelay(true); print("SteamNetworking.AllowP2PPacketRelay(" + true + ") : " + ret); } // LISTEN / CONNECT style interface functions //SteamNetworking.CreateListenSocket() // TODO //SteamNetworking.CreateP2PConnectionSocket() // TODO //SteamNetworking.CreateConnectionSocket() // TODO //SteamNetworking.DestroySocket() // TODO //SteamNetworking.DestroyListenSocket() // TODO //SteamNetworking.SendDataOnSocket() // TODO //SteamNetworking.IsDataAvailableOnSocket() // TODO //SteamNetworking.RetrieveDataFromSocket() // TODO //SteamNetworking.IsDataAvailable() // TODO //SteamNetworking.RetrieveData() // TODO //SteamNetworking.GetSocketInfo() // TODO //SteamNetworking.GetListenSocketInfo() // TODO //SteamNetworking.GetSocketConnectionType() // TODO //SteamNetworking.GetMaxPacketSize() // TODO GUILayout.EndScrollView(); GUILayout.EndVertical(); }
private void OnLobbyEntered(LobbyEnter_t result, bool failure) { P2PSessionState_t p2PSessionStateT; SteamNetworking.AllowP2PPacketRelay(true); this.SendAuthTicket(this._lobby.Owner); int num = 0; while (SteamNetworking.GetP2PSessionState(this._lobby.Owner, out p2PSessionStateT) && p2PSessionStateT.m_bConnectionActive != 1) { switch (p2PSessionStateT.m_eP2PSessionError) { case 1: { this.ClearAuthTicket(); return; } case 2: { this.ClearAuthTicket(); return; } case 3: { this.ClearAuthTicket(); return; } case 4: { int num1 = num + 1; num = num1; if (num1 > 5) { this.ClearAuthTicket(); return; } SteamNetworking.CloseP2PSessionWithUser(this._lobby.Owner); this.SendAuthTicket(this._lobby.Owner); continue; } case 5: { this.ClearAuthTicket(); return; } default: { continue; } } } this._connectionStateMap[this._lobby.Owner] = NetSocialModule.ConnectionState.Connected; SteamFriends.SetPlayedWith(this._lobby.Owner); SteamFriends.SetRichPresence("status", "Playing online."); Main.netMode = 1; Netplay.OnConnectedToSocialServer(new SocialSocket(new SteamAddress(this._lobby.Owner))); }
/// <summary> /// Initialize common values /// </summary> private void InitCommon() { SteamNetworking.AllowP2PPacketRelay(_allowRelay); MirrorpunchCommon.SetTickRate(_tickRate); }