public void GetRooms() { try { NetworkClient.Start(); Plugin.log.Debug($"Creating message..."); NetOutgoingMessage outMsg = NetworkClient.CreateMessage(); Version assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version; byte[] version = new byte[4] { (byte)assemblyVersion.Major, (byte)assemblyVersion.Minor, (byte)assemblyVersion.Build, (byte)assemblyVersion.Revision }; outMsg.Write(version); new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID()).AddToMessage(outMsg); Plugin.log.Debug($"Connecting to {channelInfos[0].ip}:{channelInfos[0].port}..."); NetworkClient.Connect(channelInfos[0].ip, channelInfos[0].port, outMsg); } catch (Exception e) { ChannelException?.Invoke(this, e); Abort(); } }
public void GetRooms() { try { NetworkClient.Start(); Misc.Logger.Info($"Creating message..."); NetOutgoingMessage outMsg = NetworkClient.CreateMessage(); outMsg.Write(Plugin.pluginVersion); new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID()).AddToMessage(outMsg); Misc.Logger.Info($"Connecting to {channelInfos[0].ip}:{channelInfos[0].port}..."); NetworkClient.Connect(channelInfos[0].ip, channelInfos[0].port, outMsg); } catch (Exception e) { ChannelException?.Invoke(this, e); Abort(); } }
public void Update() { if (NetworkClient != null && NetworkClient.Status == NetPeerStatus.Running) { NetIncomingMessage msg; while ((msg = NetworkClient.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.StatusChanged: { NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); if (status == NetConnectionStatus.Connected) { NetOutgoingMessage outMsg = NetworkClient.CreateMessage(); outMsg.Write((byte)CommandType.GetChannelInfo); outMsg.Write(channelInfos[currentChannel].channelId); NetworkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0); } else if (status == NetConnectionStatus.Disconnected) { ChannelException?.Invoke(this, new Exception("Channel refused connection!")); Abort(); } }; break; case NetIncomingMessageType.Data: { if ((CommandType)msg.ReadByte() == CommandType.GetChannelInfo) { ChannelInfo received = new ChannelInfo(msg); if (received.channelId == -1) { ChannelException?.Invoke(this, new Exception($"Channel with ID {channelInfos[currentChannel].channelId} not found!")); Abort(); return; } received.ip = channelInfos[currentChannel].ip; received.port = channelInfos[currentChannel].port; ReceivedResponse?.Invoke(this, received); if (channelInfos.Count - 1 > currentChannel) { currentChannel++; NetOutgoingMessage outMsg = NetworkClient.CreateMessage(); outMsg.Write((byte)CommandType.GetChannelInfo); outMsg.Write(channelInfos[currentChannel].channelId); NetworkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0); } else { Abort(); } } }; break; case NetIncomingMessageType.WarningMessage: Misc.Logger.Warning(msg.ReadString()); break; case NetIncomingMessageType.ErrorMessage: Misc.Logger.Error(msg.ReadString()); break; case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: Misc.Logger.Info(msg.ReadString()); break; default: Console.WriteLine("Unhandled type: " + msg.MessageType); break; } } } }