public PyPacket()
 {
     type = Macho.MachoNetMsg_Type.__Fake_Invalid_Type;
     type_string = "none";
     userID = 0;
     payload = null;
     named_payload = null;
     source = new PyAddress();
     dest = new PyAddress();
 }
Ejemplo n.º 2
0
        public PyObject Encode()
        {
            PyTuple args = new PyTuple();
            args.Items.Add(new PyToken("dbutil.CRowset"));

            PyDict dict = new PyDict();
            dict.Set("header", descriptor.Encode());

            PyObjectEx res = new PyObjectEx();
            res.IsType2 = true;

            args.Items.Add(dict);
            res.List = items.Items;

            return res;
        }
Ejemplo n.º 3
0
        public PyDict EncodeChanges()
        {
            PyDict res = new PyDict();
            PyDict tmp = new PyDict();

            // Iterate through the session data
            foreach (PyString s in session.Dictionary.Keys)
            {
                PyTuple value = session[s].As<PyTuple>();

                PyObject last = value.Items[0];
                PyObject current = value.Items[1];

                // Check if they have the same type and value
                if (last != current)
                {
                    // Add the change to the dict
                    PyTuple change = new PyTuple();

                    change.Items.Add(last);
                    change.Items.Add(current);

                    res.Set(s.Value, change);

                    // Update the session with the new last value
                    PyTuple update = new PyTuple();

                    update.Items.Add(current);
                    update.Items.Add(current);

                    // We cant modify the session here, just store it on something temporal
                    tmp[s] = update;
                }
                else
                {
                    // We havent updated anything, but this would be later set as the session
                    // This will prevent the loss of session data
                    tmp[s] = value;
                }
            }

            // Send back the session from temporal to the final storage
            session = tmp;

            return res;
        }
        public static PyDict Dict(params object[] objs)
        {
            if (objs.Length % 2 == 1)
                throw new ArgumentException("Expected pair arguments");

            var ret = new PyDict(new Dictionary<PyObject, PyObject>(objs.Length / 2));
            for (int i = 0; i < (objs.Length/2); i++)
            {
                var key = objs[i];
                var val = objs[i + 1];
                if (!(key is string))
                    throw new ArgumentException("Expected string");
                if (!(val is PyObject))
                    throw new ArgumentException("Expected PyObject");
                ret.Dictionary.Add(new PyString(key as string), val as PyObject);
            }
            return ret;
        }
Ejemplo n.º 5
0
        public bool Decode(PyObject data)
        {
            if (data.Type != PyObjectType.ObjectData)
            {
                Log.Error("ClientSessionData", "Wrong container type");
                return false;
            }

            PyObjectData container = data as PyObjectData;

            if (container.Name != "macho.sessionInitialState")
            {
                Log.Error("ClientSessionData", "Wrong container name/type");
                return false;
            }

            PyTuple args = container.Arguments as PyTuple;

            if (args.Items.Count != 2)
            {
                Log.Error("ClientSessionData", "Wrong args count");
                return false;
            }

            if (args.Items[0].Type != PyObjectType.Dict)
            {
                Log.Error("ClientSessionData", "Arguments first element is not PyDict");
                return false;
            }

            session = args.Items[0] as PyDict;

            if ((args.Items[1] is PyInt) == false)
            {
                Log.Error("ClientSessionData", "Arguments second element is not PyInt");
                return false;
            }

            clientID = (args.Items[1] as PyInt).Value;

            return true;
        }
        public bool Decode(PyObject data)
        {
            if (data.Type != PyObjectType.ObjectEx)
            {
                Log.Error("PyException", "Wrong container type");
                return false;
            }

            PyObjectEx p = data.As<PyObjectEx>();

            if (p.IsType2 == true)
            {
                Log.Error("PyException", "Wrong PyObjectEx type, expected Normal, but got Type2");
                return false;
            }

            if (p.Header.Type != PyObjectType.Tuple)
            {
                Log.Error("PyException", "Wrong item 1 type");
                return false;
            }

            PyTuple args = p.Header.As<PyTuple>();
            if (args.Items.Count != 3)
            {
                Log.Error("PyException", "Wrong tuple 1 item count, expected 3 but got " + args.Items.Count);
                return false;
            }

            if (args.Items[0].Type != PyObjectType.Token)
            {
                Log.Error("PyException", "Wrong tuple item 1 type");
                return false;
            }

            PyToken type = args.Items[0].As<PyToken>();
            exception_type = type.Token;

            if (exception_type.StartsWith("exceptions.") == false)
            {
                Log.Warning("PyException", "Trying to decode a non-exception packet: " + exception_type);
                return false;
            }

            if (args.Items[1].Type != PyObjectType.Tuple)
            {
                Log.Error("PyException", "Wrong tuple item 2 type");
                return false;
            }

            PyTuple msg = args.Items[1].As<PyTuple>();

            if (msg.Items.Count != 1)
            {
                Log.Error("PyException", "Wrong item 2 tuple count, expected 1 but got " + msg.Items.Count);
                return false;
            }

            if (msg.Items[0].Type != PyObjectType.String)
            {
                Log.Error("PyException", "Wrong tuple 2 item 1 type");
                return false;
            }

            PyString msg_data = msg.Items[0].As<PyString>();

            message = msg_data.Value;

            if (args.Items[2].Type != PyObjectType.Dict)
            {
                Log.Error("PyException", "Wrong tuple 1 item 3 type");
                return false;
            }

            PyDict info = args.Items[2].As<PyDict>();

            if (info.Contains("origin") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key origin");
                return false;
            }

            origin = info.Get("origin").As<PyString>().Value;

            if (info.Contains("reasonArgs") == false)
            {
                Log.Error("PyException", "Dict item 1 doesn has key reasonArgs");
                return false;
            }

            reasonArgs = info.Get("reasonArgs").As<PyDict>();

            if (info.Contains("clock") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key clock");
                return false;
            }

            clock = info.Get("clock").IntValue;

            if (info.Contains("loggedOnUserCount") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key loggedOnUserCount");
                return false;
            }

            loggedOnUserCount = info.Get("loggedOnUserCount");

            if (info.Contains("region") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key region");
                return false;
            }

            region = info.Get("region").As<PyString>().Value;

            if (info.Contains("reason") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key reason");
                return false;
            }

            reason = info.Get("reason").As<PyString>().Value;

            if(info.Contains("version") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key version");
                return false;
            }

            version = info.Get("version").As<PyFloat>().Value;

            if (info.Contains("build") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key build");
                return false;
            }

            build = info.Get("build").As<PyInt>().Value;

            if (info.Contains("reasonCode") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key reasonCode");
                return false;
            }

            reasonCode = info.Get("reasonCode").StringValue;

            if (info.Contains("codename") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key codename");
                return false;
            }

            codename = info.Get("codename").As<PyString>().Value;

            if (info.Contains("machoVersion") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key machoVersion");
                return false;
            }

            machoVersion = info.Get("machoVersion").As<PyInt>().Value;

            return true;
        }
        public PyObject Encode()
        {
            PyTuple header = new PyTuple();
            PyTuple args = new PyTuple();
            PyToken exception = new PyToken(exception_type);
            PyDict keywords = new PyDict();

            args.Items.Add(new PyString(reason));

            keywords.Set("reasonArgs", reasonArgs);
            keywords.Set("clock", new PyLongLong(clock));
            keywords.Set("region", new PyString(region));
            keywords.Set("reason", new PyString(reason));
            keywords.Set("version", new PyFloat(version));
            keywords.Set("build", new PyInt(build));
            keywords.Set("codename", new PyString(codename));
            keywords.Set("machoVersion", new PyInt(machoVersion));

            header.Items.Add(exception);
            header.Items.Add(args);
            header.Items.Add(keywords);

            return new PyObjectEx(false, header);
        }
Ejemplo n.º 8
0
        public PyObject GetInitVals(PyTuple args, object client)
        {
            Log.Debug("machoNet", "Called GetInitVals stub");

            if (Cache.LoadCacheFor("machoNet.serviceInfo") == false)
            {
                // Cache does not exists, create it
                PyDict dict = new PyDict();

                dict.Set("trademgr", new PyString("station"));
                dict.Set("tutorialSvc", new PyString("station"));
                dict.Set("bookmark", new PyString("station"));
                dict.Set("slash", new PyString("station"));
                dict.Set("wormholeMgr", new PyString("station"));
                dict.Set("account", new PyString("station"));
                dict.Set("gangSvc", new PyString("station"));
                dict.Set("contractMgr", new PyString("station"));

                dict.Set("LSC", new PyString("location"));
                dict.Set("station", new PyString("location"));
                dict.Set("config", new PyString("locationPreferred"));

                dict.Set("scanMgr", new PyString("solarsystem"));
                dict.Set("keeper", new PyString("solarsystem"));

                dict.Set("stationSvc", new PyNone());
                dict.Set("zsystem", new PyNone());
                dict.Set("invbroker", new PyNone());
                dict.Set("droneMgr", new PyNone());
                dict.Set("userSvc", new PyNone());
                dict.Set("map", new PyNone());
                dict.Set("beyonce", new PyNone());
                dict.Set("standing2", new PyNone());
                dict.Set("ram", new PyNone());
                dict.Set("DB", new PyNone());
                dict.Set("posMgr", new PyNone());
                dict.Set("voucher", new PyNone());
                dict.Set("entity", new PyNone());
                dict.Set("damageTracker", new PyNone());
                dict.Set("agentMgr", new PyNone());
                dict.Set("dogmaIM", new PyNone());
                dict.Set("machoNet", new PyNone());
                dict.Set("dungeonExplorationMgr", new PyNone());
                dict.Set("watchdog", new PyNone());
                dict.Set("ship", new PyNone());
                dict.Set("DB2", new PyNone());
                dict.Set("market", new PyNone());
                dict.Set("dungeon", new PyNone());
                dict.Set("npcSvc", new PyNone());
                dict.Set("sessionMgr", new PyNone());
                dict.Set("allianceRegistry", new PyNone());
                dict.Set("cache", new PyNone());
                dict.Set("character", new PyNone());
                dict.Set("factory", new PyNone());
                dict.Set("facWarMgr", new PyNone());
                dict.Set("corpStationMgr", new PyNone());
                dict.Set("authentication", new PyNone());
                dict.Set("effectCompiler", new PyNone());
                dict.Set("charmgr", new PyNone());
                dict.Set("BSD", new PyNone());
                dict.Set("reprocessingSvc", new PyNone());
                dict.Set("billingMgr", new PyNone());
                dict.Set("billMgr", new PyNone());
                dict.Set("lookupSvc", new PyNone());
                dict.Set("emailreader", new PyNone());
                dict.Set("lootSvc", new PyNone());
                dict.Set("http", new PyNone());
                dict.Set("repairSvc", new PyNone());
                dict.Set("gagger", new PyNone());
                dict.Set("dataconfig", new PyNone());
                dict.Set("lien", new PyNone());
                dict.Set("i2", new PyNone());
                dict.Set("pathfinder", new PyNone());
                dict.Set("alert", new PyNone());
                dict.Set("director", new PyNone());
                dict.Set("dogma", new PyNone());
                dict.Set("aggressionMgr", new PyNone());
                dict.Set("corporationSvc", new PyNone());
                dict.Set("certificateMgr", new PyNone());
                dict.Set("clones", new PyNone());
                dict.Set("jumpCloneSvc", new PyNone());
                dict.Set("insuranceSvc", new PyNone());
                dict.Set("corpmgr", new PyNone());
                dict.Set("warRegistry", new PyNone());
                dict.Set("corpRegistry", new PyNone());
                dict.Set("objectCaching", new PyNone());
                dict.Set("counter", new PyNone());
                dict.Set("petitioner", new PyNone());
                dict.Set("LPSvc", new PyNone());
                dict.Set("clientStatsMgr", new PyNone());
                dict.Set("jumpbeaconsvc", new PyNone());
                dict.Set("debug", new PyNone());
                dict.Set("languageSvc", new PyNone());
                dict.Set("skillMgr", new PyNone());
                dict.Set("voiceMgr", new PyNone());
                dict.Set("onlineStatus", new PyNone());
                dict.Set("gangSvcObjectHandler", new PyNone());

                Cache.SaveCacheFor("machoNet.serviceInfo", dict, DateTime.Now.ToFileTimeUtc());
            }

            PyObject srvInfo = Cache.GetCacheData("machoNet.serviceInfo");
            PyTuple res = new PyTuple();
            PyDict initvals = new PyDict();

            res.Items.Add(srvInfo);
            res.Items.Add(initvals); // Rest of the cache data

            return res;
        }
Ejemplo n.º 9
0
 public Session()
 {
     session = new PyDict();
 }
Ejemplo n.º 10
0
 private static string PrintDict(PyDict dict)
 {
     return("[PyDict " + dict.Dictionary.Count + " kvp]");
 }
        public bool Decode( PyObject data )
        {
            PyObject packet = data;

            if (packet.Type == PyObjectType.ChecksumedStream)
            {
                packet = packet.As<PyChecksumedStream>().Data;
            }

            if (packet.Type == PyObjectType.SubStream)
            {
                packet = packet.As<PySubStream>().Data;
            }

            if (packet.Type != PyObjectType.ObjectData)
            {
                return false;
            }

            PyObjectData packeto = packet.As<PyObjectData>();

            type_string = packeto.Name;

            if (packeto.Arguments.Type != PyObjectType.Tuple)
            {
                return false;
            }

            PyTuple tuple = packeto.Arguments.As<PyTuple>();

            if (tuple.Items.Count != 6)
            {
                return false;
            }

            if ((tuple.Items[0].Type != PyObjectType.IntegerVar) && ( tuple.Items[0].Type != PyObjectType.Long ) )
            {
                return false;
            }

            PyInt typer = tuple.Items[0].As<PyInt>();

            type = (Macho.MachoNetMsg_Type)typer.Value;

            if (!source.Decode(tuple.Items[1]))
            {
                return false;
            }

            if (!dest.Decode(tuple.Items[2]))
            {
                return false;
            }

            if ((tuple.Items[3].Type == PyObjectType.IntegerVar) || (tuple.Items[3].Type == PyObjectType.Long) )
            {
                userID = (uint)tuple.Items[3].As<PyInt>().Value;
            }
            else if (tuple.Items[3].Type == PyObjectType.None)
            {
                userID = 0;
            }
            else
            {
                return false;
            }

            // Payload( or call arguments )
            if ((tuple.Items[4].Type != PyObjectType.Buffer) && (tuple.Items[4].Type != PyObjectType.Tuple))
            {
                return false;
            }

            payload = tuple.Items[4].As<PyTuple>();

            if (tuple.Items[5].Type == PyObjectType.None)
            {
                named_payload = new PyDict();
            }
            else if (tuple.Items[5].Type == PyObjectType.Dict)
            {
                named_payload = tuple.Items[5].As<PyDict>();
            }
            else
            {
                return false;
            }

            return true;
        }
Ejemplo n.º 12
0
        public static PyObject DBResultToRowset(ref MySqlDataReader dat)
        {
            int column = dat.FieldCount;
            if (column == 0)
            {
                return new PyObjectData("util.Rowset", new PyDict());
            }

            PyDict args = new PyDict();

            PyList header = new PyList();
            for (int i = 0; i < column; i++)
            {
                header.Items.Add(new PyString(dat.GetName(i)));
            }

            args.Set("header", header);

            args.Set("RowClass", new PyToken("util.Row"));

            PyList rowlist = new PyList();

            while (dat.Read())
            {
                PyList linedata = new PyList();
                for (int r = 0; r < column; r++)
                {
                    linedata.Items.Add(DBColumnToPyObject(r, ref dat));
                }

                rowlist.Items.Add(linedata);
            }

            dat.Close();

            return new PyObjectData("util.Rowset", args);
        }
Ejemplo n.º 13
0
        public bool Decode(PyObject data)
        {
            PyObject packet = data;

            if (packet.Type == PyObjectType.ChecksumedStream)
            {
                packet = packet.As <PyChecksumedStream>().Data;
            }

            if (packet.Type == PyObjectType.SubStream)
            {
                packet = packet.As <PySubStream>().Data;
            }

            if (packet.Type != PyObjectType.ObjectData)
            {
                return(false);
            }

            PyObjectData packeto = packet.As <PyObjectData>();

            type_string = packeto.Name;

            if (packeto.Arguments.Type != PyObjectType.Tuple)
            {
                return(false);
            }

            PyTuple tuple = packeto.Arguments.As <PyTuple>();

            if (tuple.Items.Count != 6)
            {
                return(false);
            }

            if ((tuple.Items[0].Type != PyObjectType.IntegerVar) && (tuple.Items[0].Type != PyObjectType.Long))
            {
                return(false);
            }

            PyInt typer = tuple.Items[0].As <PyInt>();

            type = (Macho.MachoNetMsg_Type)typer.Value;

            if (!source.Decode(tuple.Items[1]))
            {
                return(false);
            }

            if (!dest.Decode(tuple.Items[2]))
            {
                return(false);
            }

            if ((tuple.Items[3].Type == PyObjectType.IntegerVar) || (tuple.Items[3].Type == PyObjectType.Long))
            {
                userID = (uint)tuple.Items[3].As <PyInt>().Value;
            }
            else if (tuple.Items[3].Type == PyObjectType.None)
            {
                userID = 0;
            }
            else
            {
                return(false);
            }

            // Payload( or call arguments )
            if ((tuple.Items[4].Type != PyObjectType.Buffer) && (tuple.Items[4].Type != PyObjectType.Tuple))
            {
                return(false);
            }

            payload = tuple.Items[4].As <PyTuple>();

            if (tuple.Items[5].Type == PyObjectType.None)
            {
                named_payload = new PyDict();
            }
            else if (tuple.Items[5].Type == PyObjectType.Dict)
            {
                named_payload = tuple.Items[5].As <PyDict>();
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 14
0
 private static string PrintDict(PyDict dict)
 {
     return "[PyDict " + dict.Dictionary.Count + " kvp]";
 }
Ejemplo n.º 15
0
        public static PyDict GetCacheHints()
        {
            PyDict result = new PyDict();

            for(int i = 0; i < LoginCacheTableSize; i ++)
            {
                result.Set(LoginCacheTable[i], GetCacheData(LoginCacheTable[i]));
            }

            return result;
        }