コード例 #1
0
 public ExtendedPacketInformation(UdpMessage msg, UdpMessageType type, string ip)
 {
     Id             = Guid.NewGuid();
     UdpMessageType = type;
     UdpMessage     = msg;
     Ip             = ip;
     Port           = msg.ReturnPort;
 }
コード例 #2
0
 public ExtendedPacketInformation(Packet packet, UdpMessageType type, string ip)
 {
     Id             = Guid.NewGuid();
     UdpMessageType = type;
     Ip             = ip;
     Port           = packet.ReturnPort;
     Packet         = packet;
 }
コード例 #3
0
        public IUdpMessage ReadPacket(Packet packet)
        {
            // this variable will be probably not needed :\.
            UdpMessageType type = (UdpMessageType)packet.ReadByte();

            switch (type)
            {
            case UdpMessageType.PACKET_UDP_SERVER_RESPONSE:
            {
                PacketUdpServerResponse r = new PacketUdpServerResponse();
                r.GameVersion = packet.ReadByte();

                if (r.GameVersion >= 4)
                {
                    byte newGrfCount = packet.ReadByte();
                    r.ActiveNewGrfs = new PacketUdpServerResponse.ActiveNewGrf[newGrfCount];

                    for (int i = 0; i < newGrfCount; ++i)
                    {
                        PacketUdpServerResponse.ActiveNewGrf grf = new PacketUdpServerResponse.ActiveNewGrf();
                        grf.GrfId = packet.ReadU32();

                        for (int j = 0; j < 16; ++j)
                        {
                            grf.Md5[j] = packet.ReadByte();
                        }
                    }
                }

                r.GameDate  = new OttdDate(packet.ReadU32());
                r.StartDate = new OttdDate(packet.ReadU32());

                r.CompaniesMax   = packet.ReadByte();
                r.CompaniesOn    = packet.ReadByte();
                r.SpectactorsMax = packet.ReadByte();

                r.ServerName     = packet.ReadString();
                r.ServerRevision = packet.ReadString();

                r.LanguageId    = packet.ReadByte();
                r.HasPassword   = packet.ReadBool();
                r.ClientsMax    = packet.ReadByte();
                r.ClientsOn     = packet.ReadByte();
                r.SpectactorsOn = packet.ReadByte();
                r.MapName       = packet.ReadString();
                r.MapWidth      = packet.ReadU16();
                r.MapHeight     = packet.ReadU16();
                r.MapSet        = packet.ReadByte();
                r.IsDedicated   = packet.ReadBool();

                return(r);
            }

            default:
                throw new NotImplementedException(type.ToString());
            }
        }
コード例 #4
0
ファイル: ISUdpServer.cs プロジェクト: gezi322/Inputshare
        private void SendMessage(UdpMessageType message, ISServerSocket client)
        {
            if (client.UdpAddress == null)
            {
                return;
            }

            udpSocket.SendTo(new byte[] { (byte)message }, client.UdpAddress);
        }
コード例 #5
0
        public void SendUdpMessage(UdpMessage msg, UdpMessageType type, string ip, int port)
        {
            var sendMsg = new SenderMessage
            {
                Body = MessagePackSerializer.Serialize(msg),
                Type = type
            };

            _sender.SendMsg(sendMsg, ip, port);
        }
コード例 #6
0
ファイル: MessageStatistics.cs プロジェクト: lovecpus/mineral
        private void AddUdpMessage(UdpMessageType type, bool flag)
        {
            switch (type)
            {
            case UdpMessageType.DISCOVER_PING:
                if (flag)
                {
                    DiscoverInPing.Add();
                }
                else
                {
                    DiscoverOutPing.Add();
                }
                break;

            case UdpMessageType.DISCOVER_PONG:
                if (flag)
                {
                    DiscoverInPong.Add();
                }
                else
                {
                    DiscoverOutPong.Add();
                }
                break;

            case UdpMessageType.DISCOVER_FIND_NODE:
                if (flag)
                {
                    DiscoverInFindNode.Add();
                }
                else
                {
                    DiscoverOutFindNode.Add();
                }
                break;

            case UdpMessageType.DISCOVER_NEIGHBORS:
                if (flag)
                {
                    DiscoverInNeighbours.Add();
                }
                else
                {
                    DiscoverOutNeighbours.Add();
                }
                break;

            default:
                break;
            }
        }
コード例 #7
0
ファイル: ISUdpServer.cs プロジェクト: gezi322/Inputshare
        private void HandleDatagram(UdpMessageType type, byte[] data, IPEndPoint senderAddress)
        {
            var sender = clientMan.GetClientFromUdpAddress(senderAddress);

            if (sender == null)
            {
                ISLogger.Write("ISUdpServer: Ignoring UDP packet from unknown address {0}", senderAddress);
                return;
            }

            if (type == UdpMessageType.ClientOK)
            {
                HandleClientOK(sender);
            }
        }
コード例 #8
0
 public void SetUdpMessageType(UdpMessageType type)
 {
     UdpMessageType = type;
 }
コード例 #9
0
ファイル: MessageStatistics.cs プロジェクト: lovecpus/mineral
 public void AddUdpOutMessage(UdpMessageType type)
 {
     AddUdpMessage(type, false);
 }
コード例 #10
0
ファイル: MessageStatistics.cs プロジェクト: lovecpus/mineral
 public void AddUdpInMessage(UdpMessageType type)
 {
     AddUdpMessage(type, true);
 }
コード例 #11
0
ファイル: Message.cs プロジェクト: lovecpus/mineral
 public Message(UdpMessageType type, byte[] data)
 {
     this.type = type;
     this.data = data;
 }