Esempio n. 1
0
 private static void Server_NewConnected(SuperWebSocket.WebSocketSession client)
 {
     Common.AppData.CQLog.Info("WebSocket Server", "New client has been connected.");
     LuaEnv.LuaStates.Run("ws_server", "ClientConnect", new {
         client
     });
 }
Esempio n. 2
0
        void ws_NewSessionConnected(SuperWebSocket.WebSocketSession session)
        {
            string           username   = Chat.GetSender(session);
            string           recivename = Chat.GetReciver(session);
            AsyncReadMessage awm        = new AsyncReadMessage(ReadMessage);

            awm.BeginInvoke(username, recivename, null, null);
        }
Esempio n. 3
0
 private static void Server_MessageReceived(SuperWebSocket.WebSocketSession client, string msg)
 {
     Common.AppData.CQLog.InfoReceive("WebSocket Server", msg);
     LuaEnv.LuaStates.Run("ws_server", "ClientMessage", new
     {
         client,
         msg
     });
 }
Esempio n. 4
0
        public static void SendData(SuperWebSocket.WebSocketSession client, Ritsukage.RUPack pack)
        {
            if (!_isRunning)
            {
                return;
            }

            _server.SendData(client, pack.Encode());
        }
Esempio n. 5
0
        public static void SendData(SuperWebSocket.WebSocketSession client, byte[] data)
        {
            if (!_isRunning)
            {
                return;
            }

            _server.SendData(client, data);
        }
Esempio n. 6
0
        public static void SendMessage(SuperWebSocket.WebSocketSession client, string msg)
        {
            if (!_isRunning)
            {
                return;
            }

            _server.SendMessage(client, msg);
        }
Esempio n. 7
0
 private static void Server_DataReceived(SuperWebSocket.WebSocketSession client, byte[] data)
 {
     Ritsukage.RUPack pack = new Ritsukage.RUPack(data);
     Common.AppData.CQLog.InfoReceive("WebSocket Server", pack.ToString());
     LuaEnv.LuaStates.Run("ws_server", "ClientData", new
     {
         client,
         pack
     });
 }
Esempio n. 8
0
        public void ProcGroupMessage(SuperWebSocket.WebSocketSession session, Message message)
        {
            string groupNo    = message.Reciver.Split('@').FirstOrDefault();
            var    groupUsers = groupUserService.GetModelList(string.Format("GroupNo='{0}'", groupNo));

            foreach (var user in groupUsers)
            {
                SuperWebSocket.WebSocketSession reciveSession = this.Chat.getSessionByName(message.Reciver);
                SendToClient(reciveSession, message);
            }
        }
Esempio n. 9
0
        public void ToSuccess(SuperWebSocket.WebSocketSession session, int type, string json)
        {
            json = new Security().Decrypt(json);

            byte[] _sendBuffer = new byte[Buffer.HEADER_SIZE + Buffer.SEND_BUFFER_SIZE];
            byte[] _data       = Encoding.UTF8.GetBytes(json);
            BitConverter.GetBytes(type).CopyTo(_sendBuffer, Buffer.PACKET_TYPE_OFFSET);

            _data.CopyTo(_sendBuffer, Buffer.HEADER_SIZE);
            session.Send(_sendBuffer, 0, Buffer.HEADER_SIZE + _data.Length);
        }
Esempio n. 10
0
 void ws_NewMessageReceived(SuperWebSocket.WebSocketSession session, string value)
 {
     try
     {
         var message = MessageHelper.Json2Object(value);
         if (message.MsgType == MedicalCrab.Core.Models.MsgType.P2P)
         {
             SuperWebSocket.WebSocketSession reciveSession = this.Chat.getSessionByName(message.Reciver);
             SendToClient(reciveSession, message, value);
         }
         else if (message.MsgType == MsgType.GROUP)
         {
             ProcGroupMessage(session, message);
         }
     }
     catch
     {
     }
 }
Esempio n. 11
0
        public void SendToClient(SuperWebSocket.WebSocketSession reciveSession, Message message, string value)
        {
            if (reciveSession != null)
            {
                reciveSession.Send(value);
                message.IsProc     = true;
                message.IsRead     = true;
                message.IsRecived  = true;
                message.SendTime   = DateTime.Now;
                message.ReciveTime = DateTime.Now;
            }
            else
            {
                message.SendTime   = DateTime.Now;
                message.ReciveTime = DateTime.MaxValue;
            }
            AsyncWriteMessage awm = new AsyncWriteMessage(WriteMessage);

            awm.BeginInvoke(message, null, null);
            //any more
        }
Esempio n. 12
0
        public static T Create <T>(SuperWebSocket.WebSocketSession ws, byte[] datas) where T : LibServerCommon.Message.IMessage
        {
            var buffer = new LibServerCommon.Network.Converter().Deserialize(datas);

            if (false == buffer.IsInit)
            {
                // buffer deserialize error
                LibServerCommon.Message.IMessage err = new Message.BufferError();
                return((T)err);
            }

            var msg = container.Resolve <T>(buffer.ProtocolType);

            if (null == msg)
            {
                // no match protocol error
                LibServerCommon.Message.IMessage err = new Message.ProtocolError();
                return((T)err);
            }

            // success
            msg.Initialize(ws, buffer);
            return(msg);
        }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EtpServer"/> class.
 /// </summary>
 /// <param name="session">The web socket session.</param>
 /// <param name="application">The serve application name.</param>
 /// <param name="version">The server application version.</param>
 /// <param name="headers">The WebSocket or HTTP headers.</param>
 public EtpServer(SuperWebSocket.WebSocketSession session, string application, string version, IDictionary <string, string> headers)
     : base(session, application, version, headers)
 {
 }
Esempio n. 14
0
 private void PreRelease()
 {
     sender  = null;
     buffer  = null;
     session = null;
 }
Esempio n. 15
0
 void server_NewSessionConnected(SuperWebSocket.WebSocketSession session)
 {
     sessions.Add(session);
 }
Esempio n. 16
0
        public void SendToClient(SuperWebSocket.WebSocketSession reciveSession, Message message)
        {
            string value = MessageHelper.Object2Json(message);

            SendToClient(reciveSession, message, value);
        }
Esempio n. 17
0
 public void Initialize(SuperWebSocket.WebSocketSession ws, Network.Buffer buffer)
 {
     this.session = ws;
     this.buffer  = buffer;
 }