public void StartServer() { ui.SetState(MultiplayerUIState.Server); MelonModLogger.Log("Starting server..."); localRigTransforms = BWUtil.GetLocalRigTransforms(); partyId = SteamClient.SteamId + "P" + DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(); RichPresence.SetActivity( new Activity() { Details = "Hosting a server", Secrets = new ActivitySecrets() { Join = SteamClient.SteamId.ToString() }, Party = new ActivityParty() { Id = partyId, Size = new PartySize() { CurrentSize = 1, MaxSize = MultiplayerMod.MAX_PLAYERS } } }); transportLayer.OnMessageReceived += TransportLayer_OnMessageReceived; transportLayer.OnConnectionClosed += TransportLayer_OnConnectionClosed; MultiplayerMod.OnLevelWasLoadedEvent += MultiplayerMod_OnLevelWasLoadedEvent; IsRunning = true; }
public void Connect(string obj) { MelonLogger.Log("Starting client and connecting"); ServerId = ulong.Parse(obj); MelonLogger.Log("Connecting to " + obj); P2PMessage msg = new P2PMessage(); msg.WriteByte((byte)MessageType.Join); msg.WriteByte(MultiplayerMod.PROTOCOL_VERSION); msg.WriteUnicodeString(SteamClient.Name); connection = transportLayer.ConnectTo(ServerId, msg); transportLayer.OnConnectionClosed += TransportLayer_OnConnectionClosed; transportLayer.OnMessageReceived += TransportLayer_OnMessageReceived; isConnected = true; localRigTransforms = BWUtil.GetLocalRigTransforms(); ui.SetState(MultiplayerUIState.Client); GunHooks.OnGunFire += BWUtil_OnFire; PlayerHooks.OnPlayerGrabObject += PlayerHooks_OnPlayerGrabObject; PlayerHooks.OnPlayerReleaseObject += PlayerHooks_OnPlayerReleaseObject; MultiplayerMod.OnLevelWasLoadedEvent += MultiplayerMod_OnLevelWasLoadedEvent; }
public void Connect(string obj) { MelonModLogger.Log("Starting client and connecting"); ServerId = ulong.Parse(obj); MelonModLogger.Log("Connecting to " + obj); P2PMessage msg = new P2PMessage(); msg.WriteByte((byte)MessageType.Join); msg.WriteByte(MultiplayerMod.PROTOCOL_VERSION); msg.WriteUnicodeString(SteamClient.Name); connection = transportLayer.ConnectTo(ServerId, msg); transportLayer.OnConnectionClosed += TransportLayer_OnConnectionClosed; transportLayer.OnMessageReceived += TransportLayer_OnMessageReceived; //SteamNetworking.SendP2PPacket(ServerId, msg.GetBytes()); isConnected = true; //PlayerHooks.OnPlayerGrabObject += PlayerHooks_OnPlayerGrabObject; //PlayerHooks.OnPlayerLetGoObject += PlayerHooks_OnPlayerLetGoObject; localRigTransforms = BWUtil.GetLocalRigTransforms(); //SteamNetworking.OnP2PSessionRequest = OnP2PSessionRequest; //SteamNetworking.OnP2PConnectionFailed = OnP2PConnectionFailed; ui.SetState(MultiplayerUIState.Client); }