Ejemplo n.º 1
0
 public void Process(SocketClient client, DataPacket packet)
 {
     if(client.User != null) {
         UserInput input = new UserInput("shot");
         input["nX"] = packet["nX"];
         input["nY"] = packet["nY"];
         client.User.AddInput(input);
     }
 }
Ejemplo n.º 2
0
 public void Process(SocketClient client, DataPacket packet)
 {
     if (client.User != null) {
         UserInput input = new UserInput("charMove");
         input["d"] = ((FieldData)packet["d"]).Value;
         client.User.AddInput(input);
         //client.User.Char.Target =
     }
     /*if(client.User != null) {
         client.User.Name = packet["n"].ToString();
     }*/
 }
Ejemplo n.º 3
0
 public void Process(SocketClient client, DataPacket packet)
 {
     if(client.User != null && client.User.Char != null) {
         if(GameObject.Time - client.User.lastEmotion > User.emotionDelay) {
             client.User.lastEmotion = GameObject.Time;
             {
                 DataPacket pckt = PacketFactory.Make("emotionAdd");
                 if(pckt != null) {
                     pckt["id"] = client.User.Char.ID;
                     pckt["t"] = int.Parse(packet["t"].ToString());
                     SocketServer.inst.Publish(pckt);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 public virtual bool Unsubscribe(SocketClient client)
 {
     if(this.subscribers.TryRemove(client.ID, out client)) {
         --count;
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 5
0
 public virtual bool Subscribe(SocketClient client)
 {
     client.Stopped += ClientStopped;
     if(this.subscribers.TryAdd(client.ID, client)) {
         ++count;
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 6
0
 private void ClientStopped(SocketClient client)
 {
     this.Unsubscribe(client);
 }
Ejemplo n.º 7
0
 public void TriggerEvents(SocketClient client)
 {
     this.packet.Trigger(client, this);
 }
Ejemplo n.º 8
0
        public IPacket Read(SocketClient socket)
        {
            try {
                bool fin = (socket.Buffer[0] & 0x80) == 0x80;

                bool rsv1 = (socket.Buffer[0] & 0x40) == 0x40;
                bool rsv2 = (socket.Buffer[0] & 0x20) == 0x20;
                bool rsv3 = (socket.Buffer[0] & 0x10) == 0x10;

                OpCode opCode = (OpCode)((socket.Buffer[0] & 0x8) | (socket.Buffer[0] & 0x4) | (socket.Buffer[0] & 0x2) | (socket.Buffer[0] & 0x1));

                bool mask = (socket.Buffer[1] & 0x80) == 0x80;

                byte payload = (byte)((socket.Buffer[1] & 0x40) | (socket.Buffer[1] & 0x20) | (socket.Buffer[1] & 0x10) | (socket.Buffer[1] & 0x8) | (socket.Buffer[1] & 0x4) | (socket.Buffer[1] & 0x2) | (socket.Buffer[1] & 0x1));
                ulong length = 0;

                switch(payload) {
                    case 126:
                        byte[] bytesUShort = socket.Receive(2);
                        if(bytesUShort != null) {
                            length = BitConverter.ToUInt16(bytesUShort.Reverse().ToArray(), 0);
                        }
                        break;
                    case 127:
                        byte[] bytesULong = socket.Receive(8);
                        if(bytesULong != null) {
                            length = BitConverter.ToUInt16(bytesULong.Reverse().ToArray(), 0);
                        }
                        break;
                    default:
                        length = payload;
                        break;
                }

                byte[] maskKeys = null;
                if(mask) {
                    maskKeys = socket.Receive(4);
                }

                WSPacket packet = null;

                if(length > 0) {
                    byte[] data = socket.Receive((int)length);

                    if(mask) {
                        for(int i = 0; i < data.Length; ++i) {
                            data[i] = (byte)(data[i] ^ maskKeys[i % 4]);
                        }
                    }

                    ushort closeCode = 0;
                    if(opCode == OpCode.Close && data.Length == 2) {
                        closeCode = BitConverter.ToUInt16(((byte[])data.Clone()).Reverse().ToArray(), 0);
                    }

                    if(closeCode != 0) {
                        packet = new WSPacket(data, opCode, closeCode);
                    } else {
                        packet = new WSPacket(data, opCode);
                    }
                } else {
                    packet = new WSPacket(null, opCode);
                }

                return packet;

            } catch(Exception ex) {
                Log.Add("websocket transport protocol Read exception: " + ex.ToString());
            }

            return null;
        }
Ejemplo n.º 9
0
 public void Trigger(SocketClient client, DataPacket packet)
 {
     foreach(IPacketEvent evnt in this.events) {
         evnt.Process(client, packet);
     }
 }
Ejemplo n.º 10
0
 public void Process(SocketClient client, DataPacket packet)
 {
     if(client.User != null) {
         client.User.Name = packet["n"].ToString();
     }
 }