Esempio n. 1
0
        public void Send(SessionState sessionState, ISendProtocol sendProtocol, EventTypes eventType, Int32 refNum)
        {
            var header = new Header
            {
                eventType = eventType.ToString(),
                refNum    = refNum,
            };

            try
            {
                header.message = sendProtocol?.SerializeJSON(new Message
                {
                    sessionState = sessionState,
                    header       = header,
                });
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            var json = JsonConvert.SerializeObject(new object[] {
                header.eventType.ToString(),
                header.refNum,
                header.message,
            });

            WebAsyncSocket.Send(sessionState, connectionState, json);
        }
        public static void SendToUserIDs(List <UInt32> UserIDs, ISendProtocol sendProtocol, EventTypes eventType, Int32 refNum)
        {
            foreach (var UserID in UserIDs)
            {
                var state = sessionStates[UserID];

                state.Send(sendProtocol, eventType, refNum);
            }
        }
 public static void SendToServer(ISendProtocol sendProtocol, EventTypes eventType, Int32 refNum)
 {
     sessionStates.Values
     .Where(c => c.successfullyConnected)
     .ToList()
     .ForEach(s =>
     {
         s.Send(sendProtocol, eventType, refNum);
     });
 }
 public static void SendToRoomID(Int16 RoomID, UInt32 excludeUserID, ISendProtocol sendProtocol, EventTypes eventType, Int32 refNum)
 {
     sessionStates.Values
     .Where(c => excludeUserID == 0 || c.UserID != excludeUserID)
     .Where(c => c.successfullyConnected)
     .Where(c => c.RoomID == RoomID)
     .ToList()
     .ForEach(s =>
     {
         s.Send(sendProtocol, eventType, refNum);
     });
 }
        public void Send(SessionState sessionState, ISendProtocol sendProtocol, EventTypes eventType, Int32 refNum)
        {
            if (sendProtocol != null)
            {
                var header = new Header
                {
                    eventType = eventType.ToString(),
                    refNum    = refNum,
                };
                var data = new byte[0];

                try
                {
                    data = sendProtocol.Serialize(new Message
                    {
                        sessionState = sessionState,
                        header       = header,
                    });
                }
                catch (Exception ex)
                {
                    ex.Log();
                }

                header.length = (UInt32)(data == null ? 0 : data.Length);

                switch (eventType)
                {
                case EventTypes.MSG_LISTOFALLROOMS:
                    header.refNum = (Int32)((MSG_LISTOFALLROOMS)sendProtocol).nbrRooms;

                    break;

                case EventTypes.MSG_LISTOFALLUSERS:
                    header.refNum = (Int32)((MSG_LISTOFALLUSERS)sendProtocol).nbrUsers;

                    break;
                }

                PalaceAsyncSocket.Send(sessionState, header.Serialize(data));
            }
            else
            {
                var header = new Header
                {
                    eventType = eventType.ToString(),
                    length    = (UInt32)0,
                    refNum    = refNum,
                };

                PalaceAsyncSocket.Send(sessionState, header.Serialize());
            }
        }
Esempio n. 6
0
 private void MqttClient_ApplicationMessageReceived(object sender,
                                                    MqttApplicationMessageReceivedEventArgs e)
 {
     try
     {
         byte[]        bytes        = e.ApplicationMessage.Payload;
         var           protocolId   = (int)bytes[0];
         ISendProtocol sendProtocol = _sendProtocolFactory.Create(protocolId);
         sendProtocol?.Receive(bytes);
     }
     catch (Exception exception)
     {
         _logger.LogError(exception.InnerException?.Message ?? exception.Message);
     }
 }
Esempio n. 7
0
 public LoginHandler(ISendProtocol sendProtocol)
 {
     this.sendProtocol = sendProtocol;
 }
 public static void Send(this SessionState sessionState, ISendProtocol sendProtocol, EventTypes eventType, Int32 refNum)
 {
     sessionState.driver.Send(sessionState, sendProtocol, eventType, refNum);
 }
        public static void SendToUserID(UInt32 UserID, ISendProtocol sendProtocol, EventTypes eventType, Int32 refNum)
        {
            var state = sessionStates[UserID];

            state.Send(sendProtocol, eventType, refNum);
        }
Esempio n. 10
0
 public HeartBeatHandler(ISendProtocol sendProtocol, IPlayer player)
 {
     this.sendProtocol = sendProtocol;
     this.player       = player;
 }