Exemplo n.º 1
0
        /// <summary> 登录测试
        /// </summary>
        /// <param name="stationId"></param>
        /// <param name="userId"></param>
        /// <param name="pwd"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string LoginTest(string stationId, string userId, string pwd, string code)
        {
            LoginProtocol protocol = GetLoginProtocol();

            protocol.StationId      = stationId;
            protocol.UserId         = userId;
            protocol.Password       = pwd;
            protocol.PermissionCode = code;

            MessageProtocol mp = ServiceAgent.SendAndReceiveMessage(protocol);

            if (mp != null && mp.GetRealProtocol() is ResultProtocol)
            {
                ResultProtocol result = mp.GetRealProtocol() as ResultProtocol;
                if (result.Result == DataSources.EnumResultType.Success.ToString("d"))
                {
                    return(string.Empty);
                }
                else
                {
                    string msg = "登录消息(数据端口):" + DataSources.GetDescription(typeof(DataSources.EnumResultType), result.Result);
                    //写入日志
                    Log.writeCloudLog(msg);
                    return(DataSources.GetDescription(typeof(DataSources.EnumResultType), result.Result));
                }
            }
            return("返回协议格式不正确");
        }
Exemplo n.º 2
0
 public static void Join(int lobbyId)
 {
     if (ws.IsAlive)
     {
         ws.Send(MessageProtocol.JoinRequest(lobbyId, Lobby.user.username));
     }
 }
Exemplo n.º 3
0
 public MessageChannel(MessageProtocol protocol, string address, MessageActor port)
     : this()
 {
     this.Protocol = protocol;
     this.Address  = address;
     this.Port     = (int)port;
 }
Exemplo n.º 4
0
 public MessageChannel(MessageProtocol protocol, string address, int port)
     : this()
 {
     this.Protocol = protocol;
     this.Address  = address;
     this.Port     = port;
 }
Exemplo n.º 5
0
        public static MessageUM PrepareReceivedData(byte[] text, Encoding _Encoding)
        {
            var gotMessage = new MessageUM();

            try
            {
                var data = Decrypt(_Encoding.GetString(text));


                if (new System.Text.RegularExpressions.Regex("websocket").IsMatch(data))
                {
                    var length = data.Substring(0, data.IndexOf("\r\n")).Length;
                    data = GetDecodedData(text.Take(length).ToArray(), length);
                }

                if (data.Trim() == "?")
                {
                    gotMessage.Text = "?";
                }

                if (data.Length < FromIdLength + ToIdLength)
                {
                    return(gotMessage);
                }
                gotMessage = MessageProtocol.getDecodedMessage(data);
                return(gotMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error In PreaparingData Method : " + e.Message);
                return(null);
            }
        }
Exemplo n.º 6
0
        public void WhenControlConnectionHandshakeSuccessConfigurationReturned()
        {
            // arrange
            var messageProtocol            = new MessageProtocol();
            var configurationReader        = new Mock <ConfigurationReader>();
            var controlConnectionHandshake = new ControlConnectionHandshake(messageProtocol, configurationReader.Object);

            var binaryReader = new Mock <BinaryReader>(new MemoryStream());
            var binaryWriter = new Mock <BinaryWriter>(new MemoryStream());

            binaryReader.Setup(x => x.ReadByte())
            .Returns(MessageTypes.Configuration);

            const string configurationJson = "{\"RunId\":1,\"HeartbeatInterval\":2,\"Exclusions\":[\"Exclusion\"],\"Inclusions\":[\"Inclusion\"],\"BufferMemoryBudget\":3,\"QueueRetryCount\":4,\"NumDataSenders\":5}";

            binaryReader.Setup(x => x.ReadBytes(sizeof(short)))
            .Returns(new byte[] { 0x0, Convert.ToByte(configurationJson.Length) });

            binaryReader.Setup(x => x.ReadBytes(configurationJson.Length))
            .Returns(System.Text.Encoding.UTF8.GetBytes(configurationJson));

            var connection = new Connection(binaryReader.Object, binaryWriter.Object);

            // act
            var configuration = controlConnectionHandshake.PerformHandshake(connection);

            // assert
            binaryWriter.Verify(x => x.Write(MessageTypes.Hello), Times.Once);
            binaryWriter.Verify(x => x.Write(messageProtocol.ProtocolVersion), Times.Once());

            Assert.IsNotNull(configuration);
        }
Exemplo n.º 7
0
        public void WhenControlConnectionHandshakeHasUnknownErrorExceptionThrown()
        {
            // arrange
            var messageProtocol            = new MessageProtocol();
            var configurationReader        = new Mock <ConfigurationReader>();
            var controlConnectionHandshake = new ControlConnectionHandshake(messageProtocol, configurationReader.Object);

            var binaryReader = new Mock <BinaryReader>(new MemoryStream());
            var binaryWriter = new Mock <BinaryWriter>(new MemoryStream());

            binaryReader.Setup(x => x.ReadByte())
            .Returns(0xFE);

            var connection = new Connection(binaryReader.Object, binaryWriter.Object);

            // act
            try
            {
                controlConnectionHandshake.PerformHandshake(connection);
            }
            catch (HandshakeException e)
            {
                Assert.AreEqual("Handshake operation failed with unexpected reply: 254", e.Message);
            }
        }
Exemplo n.º 8
0
 public static void DisplayUpdate()
 {
     if (ws.IsAlive)
     {
         ws.Send(MessageProtocol.DisplayUpdate(Lobby.user));
     }
 }
Exemplo n.º 9
0
 public static void Kick(int lobbyId, int userId)
 {
     if (ws.IsAlive)
     {
         ws.Send(MessageProtocol.Kick(lobbyId, userId));
     }
 }
        public void WhenDataConnectionHandshakeHasErrorExceptionThrown()
        {
            // arrange
            var messageProtocol         = new MessageProtocol();
            var dataConnectionHandshake = new DataConnectionHandshake(messageProtocol);

            var binaryReader = new Mock <BinaryReader>(new MemoryStream());
            var binaryWriter = new Mock <BinaryWriter>(new MemoryStream());

            binaryReader.Setup(x => x.ReadByte())
            .Returns(MessageTypes.Error);

            const string errorString = "Error";

            binaryReader.Setup(x => x.ReadBytes(sizeof(short)))
            .Returns(new byte[] { 0x0, Convert.ToByte(errorString.Length) });

            binaryReader.Setup(x => x.ReadBytes(errorString.Length))
            .Returns(System.Text.Encoding.UTF8.GetBytes(errorString));

            var connection = new Connection(binaryReader.Object, binaryWriter.Object);

            try
            {
                // act
                dataConnectionHandshake.PerformHandshake(1, connection);
            }
            catch (HandshakeException e)
            {
                Assert.AreEqual("Error", e.Message);
            }

            // assert
            binaryWriter.Verify(x => x.Write(MessageTypes.DataHello), Times.Once);
        }
        public void WhenDataConnectionHandshakeHasUnknownErrorExceptionThrown()
        {
            // arrange
            var messageProtocol         = new MessageProtocol();
            var dataConnectionHandshake = new DataConnectionHandshake(messageProtocol);

            var binaryReader = new Mock <BinaryReader>(new MemoryStream());
            var binaryWriter = new Mock <BinaryWriter>(new MemoryStream());

            binaryReader.Setup(x => x.ReadByte())
            .Returns(0xFE);

            var connection = new Connection(binaryReader.Object, binaryWriter.Object);

            try
            {
                // act
                dataConnectionHandshake.PerformHandshake(1, connection);
            }
            catch (HandshakeException e)
            {
                Assert.AreEqual("Handshake operation failed with unexpected reply: 254", e.Message);
            }

            // assert
            binaryWriter.Verify(x => x.Write(MessageTypes.DataHello), Times.Once);
        }
Exemplo n.º 12
0
    void HandleAckQueue()
    {
        List <AckInfo> acksDone     = new List <AckInfo>();
        List <int>     finalAckList = new List <int>();

        for (var i = 0; i < m_AcksToSend.Count; ++i)
        {
            var ack = m_AcksToSend[i];
            ack.attempts = ack.attempts + 1;
            // Debug.Log ("ACK " + ack.sequenceNumber + " attempts: " + ack.attempts);
            if (ack.attempts > 10)
            {
                acksDone.Add(ack);
                continue;
            }
            finalAckList.Add(ack.sequenceNumber);
        }
        // Debug.Log ("dead acks: " + acksDone.Count);
        foreach (var ack in acksDone)
        {
            m_AcksToSend.Remove(ack);
        }
        if (finalAckList.Count > 0)
        {
            Send(PacketId.ACK, MessageProtocol.PackData(finalAckList.ToArray()));
        }
    }
Exemplo n.º 13
0
 public static void PositionUpdate(int lobbyId, float px, float py, float vx, float vy)
 {
     if (ws.IsAlive)
     {
         ws.Send(MessageProtocol.PositionUpdate(lobbyId, px, py, vx, vy));
     }
 }
Exemplo n.º 14
0
 public static void Fire(int lobbyId, string weapon, float px, float py, float vx, float vy)
 {
     if (ws.IsAlive)
     {
         ws.Send(MessageProtocol.Fire(lobbyId, weapon, px, py, vx, vy));
     }
 }
Exemplo n.º 15
0
 public static void Start(int lobbyId)
 {
     if (ws.IsAlive)
     {
         ws.Send(MessageProtocol.Start(lobbyId));
     }
 }
Exemplo n.º 16
0
 public static void SwapTeam(int lobbyId, int userId, string newTeam)
 {
     if (ws.IsAlive)
     {
         ws.Send(MessageProtocol.SwapTeam(lobbyId, userId, newTeam));
     }
 }
Exemplo n.º 17
0
 public static void Promote(int lobbyId, int newOwner)
 {
     if (ws.IsAlive)
     {
         ws.Send(MessageProtocol.Promote(lobbyId, newOwner));
     }
 }
Exemplo n.º 18
0
 public ProtocolVersion(IErrorHandler errorHandler)
 {
     _errorHandler              = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler));
     MessageProtocol            = new MessageProtocol();
     ConfigurationReader        = new ConfigurationReader();
     ControlConnectionHandshake = new ControlConnectionHandshake(MessageProtocol, new ConfigurationReader());
     DataConnectionHandshake    = new DataConnectionHandshake(MessageProtocol);
 }
 public PairingCodeMessage(MessageProtocol pairingCodeType)
     : base(pairingCodeType)
 {
     if (pairingCodeType != MessageProtocol.PIN_CODE && pairingCodeType != MessageProtocol.COLOR_CODE)
     {
         throw new ArgumentException("Unknown pairing code type: " + pairingCodeType);
     }
 }
    private void ReceiveMessage(BaseProtocol protocol)
    {
        MessageProtocol message = protocol as MessageProtocol;

        PrintToConsole(string.Format("{0}: {1}", message.from_client, message.message));

        Debug.LogFormat("Recived message: {0} from {2} Len: {1}", message.message, message.message.Length, message.from_client);
    }
    private void ProcessHandshakeData(MessageObject msg)
    {
        //Handshake error
        if (!msg.ContainsKey("code") || !msg.ContainsKey("sys") || Convert.ToInt32(msg["code"]) != 200)
        {
            throw new Exception("Handshake error! Please check your handshake config.");
        }

        //Set compress data
        MessageObject sys = (MessageObject)msg["sys"];

        MessageObject dict = new MessageObject();

        if (sys.ContainsKey("dict"))
        {
            dict = (MessageObject)sys["dict"];
        }

        MessageObject protos       = new MessageObject();
        MessageObject serverProtos = new MessageObject();
        MessageObject clientProtos = new MessageObject();

        if (sys.ContainsKey("protos"))
        {
            protos       = (MessageObject)sys["protos"];
            serverProtos = (MessageObject)protos["server"];
            clientProtos = (MessageObject)protos["client"];
        }

        messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos);

        //Init heartbeat service
        int interval = 0;

        if (sys.ContainsKey("heartbeat"))
        {
            interval = Convert.ToInt32(sys["heartbeat"]);
        }
        heartBeatService = new HeartBeatService(interval, this);

        if (interval > 0)
        {
            heartBeatService.Start();
        }

        //send ack and change protocol state
        handshake.Ack();
        this.state = enProtocolState.working;

        //Invoke handshake callback
        MessageObject user = new MessageObject();

        if (msg.ContainsKey("user"))
        {
            user = (MessageObject)msg["user"];
        }
        handshake.InvokeCallback(user);
    }
Exemplo n.º 22
0
        public void ReadMessage()
        {
            NetworkStream nStream = this.sock.GetStream();
            BinaryReader  reader  = new BinaryReader(nStream);

            this.dataLength = reader.ReadInt32();
            this.protocol   = (MessageProtocol)reader.ReadInt16();
            this.message    = reader.ReadString();
        }
Exemplo n.º 23
0
 public Message()
 {
     this.data         = default(T);
     this.gameTime     = null;
     this.type         = MessageType.Unknown;
     this.handled      = false;
     this.uniqueTarget = -1;
     this.protocol     = MessageProtocol.Request;
 }
Exemplo n.º 24
0
        public static void RegisterLogic(string clientMessage, Socket socket)
        {
            User newUser = new User(clientMessage);

            UsersList.Add(newUser);
            Message serverMessage = new Message(HeaderConstants.Response, CommandConstants.Register, "Usuario Registrado");

            MessageProtocol.SendMessage(socket, serverMessage);
        }
Exemplo n.º 25
0
 public static void Ping()
 {
     if (ws.IsAlive)
     {
         ws.Send(MessageProtocol.Ping());
         stopWatch.Reset();
         stopWatch.Start();
     }
 }
Exemplo n.º 26
0
 /// <summary>
 /// 获取心跳包
 /// </summary>
 /// <returns></returns>
 private static MessageProtocol GetHeartBeat()
 {
     MessageProtocol mp = new MessageProtocol();
     mp.StationId = GlobalStaticObj_Server.Instance.StationID;
     mp.MessageId = LoginProtocol.id;
     //mp.SerialNumber = GlobalStaticObj_Server.Instance.SerialNumber.ToString();            
     mp.SubMessageId = SubMessageId;
     mp.TimeSpan = TimeHelper.GetTimeInMillis();
     return mp;
 }       
Exemplo n.º 27
0
        public NetworkConnection(TcpClient c)
        {
            client = c;

            messageProtocol = new MessageProtocol();
            messageProtocol.MessageComplete += MessageProtocol_MessageComplete;

            thread = new Thread(ThreadProc);
            thread.Start();
        }
Exemplo n.º 28
0
        public LrDevelopController(MessageProtocol <LrDevelopController> messageProtocol) : base(messageProtocol)
        {
            _parameterLookup = new Dictionary <string, IParameter>();
            foreach (var parameter in Parameters.Parameters.AllParameters)
            {
                _parameterLookup[parameter.Name] = parameter;
            }

            _parameterChangedHandlers = new ConcurrentDictionary <IParameter, ParameterChangedHandler>();
        }
Exemplo n.º 29
0
        public static void protocolProcess(byte[] bytes)
        {
            JsonNode dict         = new JsonClass();
            JsonNode serverProtos = new JsonClass();
            JsonNode clientProtos = new JsonClass();

            MessageProtocol messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos);
            Package         pkg             = PackageProtocol.decode(bytes);

            messageProtocol.decode(pkg.body);
        }
        public static void protocolProcess(byte[] bytes)
        {
            MessageObject dict         = new MessageObject();
            MessageObject serverProtos = new MessageObject();
            MessageObject clientProtos = new MessageObject();

            MessageProtocol messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos);
            Package         pkg             = PackageProtocol.Decode(bytes);

            messageProtocol.Decode(pkg.body);
        }
Exemplo n.º 31
0
        public void SendMessage(ChatMessage message)
        {
            var ptc = new MessageProtocol();

            ptc.Message = message;
            var packet = new BasicPacket();

            packet.Opcode = 9;
            packet.Data   = ptc.ToBytes();
            _client.Write(packet.ToBytes());
        }
Exemplo n.º 32
0
        /// <summary>
        /// 获取心跳包
        /// </summary>
        /// <returns></returns>
        private static MessageProtocol GetHeartBeat()
        {
            MessageProtocol mp = new MessageProtocol();

            mp.StationId = GlobalStaticObj_Server.Instance.StationID;
            mp.MessageId = LoginProtocol.id;
            //mp.SerialNumber = GlobalStaticObj_Server.Instance.SerialNumber.ToString();
            mp.SubMessageId = SubMessageId;
            mp.TimeSpan     = TimeHelper.GetTimeInMillis();
            return(mp);
        }
Exemplo n.º 33
0
 public Message(MessageProtocol command)
 {
     this.Command = command;
 }
 public TouchEventMessage(MessageProtocol command)
     : base(command)
 {
 }
Exemplo n.º 35
0
 public OutgoingMessage(MessageProtocol command)
     : base(command)
 {
 }
 public IncomingBodyLessMessage(MessageProtocol command)
     : base(command)
 {
 }