public NativeFunction(string name, string args)
 {
     Guid = "";
     Response = 0;
     Name = name;
     Args = args;
     Data = new DataStream();
 }
 public NativeFunction()
 {
     Guid = "";
     Response=0;
     Name = "";
     Args = "";
     Data = new DataStream();
 }
Ejemplo n.º 3
0
 public void SendNativeFunction(Server server, string guid,string name, string args, DataStream data)
 {
     Log.Debug("SendNativeFunction: "+name);
     Packet sp = new Packet(Packet.Opcodes.FunctionRequest);
     sp.AddString(guid);
     sp.AddString(name); // name
     sp.AddInt32(0); // response
     sp.AddString(args);
     sp.AddData(data.Data,data.Length);
     _Client.SendPacket(server, sp);
 }
        public void ProcessPacket(object args)
        {
            Server server = ((ProcessPacketParams)args).server;
            Packet pak = ((ProcessPacketParams)args).packet;
            if (!server.IsConnected) return;
            //Log.Debug("Packet received: " + pak.Opcode.ToString());

            if (pak.Opcode == (byte)Packet.Opcodes.Auth)
            { // authentication response
                Log.Debug("Auth pak receive");
                bool success = pak.ReadBool();
                if (success) { server.IsAuthenticated = true; Log.Debug("Auth success."); }
                else {server.IsAuthenticated = false; Log.Debug("Auth failed.");}
            }
            if (!server.IsAuthenticated) return;
            if (pak.Opcode == (byte)Packet.Opcodes.Ping)
            {
                _Client.PakSender.SendPingReply(server);
            }

            if (pak.Opcode == (byte)Packet.Opcodes.Callback)
            {
                string callbackname = pak.ReadString();
                Log.Debug("Callback Received: " + callbackname);

                byte[] callbackdata = pak.ReadData(pak.Length - pak.Pos);

                DataStream sdata = new DataStream();
                sdata.Data = callbackdata;
                sdata.Length = (ushort)callbackdata.Length;
                InternalEvents.FireOnCallbackReceived(null, new OnCallbackReceivedEventArgs(server,_Client,callbackname,sdata));

                //return;
            }

            if (pak.Opcode == (byte)Packet.Opcodes.FunctionRequest)
            {
                //Log.Debug("function request received");
                string funcname = pak.ReadString();
                string callbackname = pak.ReadString();
                string paramtypes = pak.ReadString();
                //byte[] funcdata = pak.ReadData(pak.Length - pak.Pos);
                object[] funcparams = new object[paramtypes.Length];

                char[] cparamtypes = paramtypes.ToCharArray();
                for (int i=0;i<paramtypes.Length;i++)
                {
                    switch (cparamtypes[i])
                    {
                        case 'i':
                            funcparams[i] = pak.ReadInt32();
                            break;
                        case 'f':
                            funcparams[i] = pak.ReadFloat32();
                            break;
                        case 's':
                            funcparams[i] = pak.ReadString();
                            break;
                    }
                }

                //DataStream sdata = new DataStream();
                //sdata.Data = funcdata;
                //sdata.Length = (ushort)funcdata.Length;
                //Log.Debug("funcreq: " + funcname);
                InternalEvents.FireOnFunctionRequestReceived(null, new OnFunctionRequestReceivedEventArgs(server, _Client, funcname,callbackname,paramtypes,funcparams));

                //return;
            }

            if (pak.Opcode == (byte)Packet.Opcodes.Test)
            {
                Log.Debug("Packet Test received");
                Log.Debug(pak.ReadString());
                Log.Debug(pak.ReadInt32().ToString());
                Log.Debug(pak.ReadByte().ToString());
                Log.Debug(pak.ReadFloat32().ToString());
                Log.Debug(pak.ReadString());

            }
              // Log.Debug("paklen: "+pak.Data.Length);
            pak.Pos = 0;
            InternalEvents.FireOnPacketReceived(this,new OnPacketReceivedEventArgs(server,_Client,pak));
        }
 public OnCallbackReceivedEventArgs(Server server, Client client, string callbackname, DataStream data)
 {
     _Server = server;
     _Client = client;
     CallbackName = callbackname;
     Data = data;
 }