Exemplo n.º 1
0
        private void ConnectCallback(IAsyncResult ar)
        {
            try
            {
                Socket tClient = (Socket)ar.AsyncState;

                stateObj.workSocket = tClient;

                BSONObject request = new BSONObject();
                request["msg"]  = "auth";
                request["note"] = "(none)";
                request["mID"]  = HardwareID.GetHwid();


                byte[] requestData = SimpleBSON.Dump(request);


                tClient.BeginSend(requestData, 0, requestData.Length, SocketFlags.None, new AsyncCallback(SendCallback), stateObj);

                tClient.BeginReceive(stateObj.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), stateObj);
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
    private void writeSocket()
    {
        if (!socket_ready)
        {
            return;
        }

        Queue <IServerCmd> srvCmdList = this.cmdMgr.getServerCmds();

        if (srvCmdList.Count <= 0)
        {
            return;
        }
        //Debug.Log("Write Socket");
        for (var i = 0; i < srvCmdList.Count; i++)
        {
            IServerCmd cmd = srvCmdList.Dequeue();
            BSONObject obj = cmd.encode();
            byte[]     raw = SimpleBSON.Dump(obj);

            socket_writer.Write(raw, 0, raw.Length);

            socket_writer.Flush();
            //Debug.Log (" - Command written!");
        }
    }
Exemplo n.º 3
0
        public void WriteSingleObject()
        {
            BSONObject obj = new BSONObject();

            obj ["Blah"] = 1;

            string bson = MiscellaneousUtils.BytesToHex(SimpleBSON.Dump(obj));

            Assert.AreEqual("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00", bson);
        }
Exemplo n.º 4
0
        public void WriteArray()
        {
            byte[] data = MiscellaneousUtils.HexToBytes("31-00-00-00-04-42-53-4f-4e-00-26-00-00-00-02-30-00-08-00-00-00-61-77-65-73-6f-6d-65-00-01-31-00-33-33-33-33-33-33-14-40-10-32-00-c2-07-00-00-00-00");

            BSONObject obj = new BSONObject();

            obj ["BSON"] = new BSONArray();
            obj ["BSON"].Add("awesome");
            obj ["BSON"].Add(5.05);
            obj ["BSON"].Add(1986);

            byte[] target = SimpleBSON.Dump(obj);
            Assert.IsTrue(MiscellaneousUtils.ByteArrayCompare(target, data) == 0);
        }
Exemplo n.º 5
0
        private byte[] CreateServerStatusMessagePayload(MongoConnectionStringBuilder connectionStringBuilder)
        {
            byte[] message;
            int    commandLength;

            //Write the message first because we need the it's length
            using (var commandMemoryStream = new MemoryStream())
                using (var commandWriter = new BinaryWriter(commandMemoryStream, new UTF8Encoding(), true))
                {
                    //Query options
                    commandWriter.Write(0);
                    //Collection name
                    commandWriter.Write($"{connectionStringBuilder.Database}.$cmd".ToArray());
                    //cstring's require a \x00 at the end.
                    commandWriter.Write('\x00');
                    //Number to skip
                    commandWriter.Write(0);
                    //Number to return
                    commandWriter.Write(-1);

                    var commandBSON = new BSONObject
                    {
                        ["serverStatus"] = 1.0
                    };
                    commandWriter.Write(SimpleBSON.Dump(commandBSON));
                    commandWriter.Flush();

                    commandLength = (int)commandMemoryStream.Length;
                    message       = new byte[16 + commandLength];
                    Array.Copy(commandMemoryStream.ToArray(), 0, message, 16, commandLength);
                }

            using (var messageMemoryStream = new MemoryStream(message))
                using (var completeMessageWriter = new BinaryWriter(messageMemoryStream, new UTF8Encoding(), true))
                {
                    //Message length
                    completeMessageWriter.Write(16 + commandLength);
                    //Request Id
                    completeMessageWriter.Write(0);
                    //Response To
                    completeMessageWriter.Write(0);
                    //Operation Code
                    completeMessageWriter.Write(2004);
                    completeMessageWriter.Flush();
                }
            return(message);
        }
Exemplo n.º 6
0
        private void sendchatmsg_Click(object sender, EventArgs e)
        {
            try
            {
                BSONObject request = new BSONObject();
                request["msg"]  = "chat_req";
                request["note"] = chatbox.Text;


                byte[] requestData = SimpleBSON.Dump(request);

                stateObj.workSocket.BeginSend(requestData, 0, requestData.Length, SocketFlags.None, new AsyncCallback(SendCallback), stateObj);
                chatbox.Text = "";
            }
            catch
            {
            }
        }
Exemplo n.º 7
0
        private byte[] OnPacket(byte[] revBuffer, String from)
        {
            // Remove padding and load the bson.
            byte[] data = new byte[revBuffer.Length - 4];
            Buffer.BlockCopy(revBuffer, 4, data, 0, data.Length);

            BSONObject packets = null;

            try
            {
                packets = SimpleBSON.Load(data);
            }catch { }

            if (packets == null || !packets.ContainsKey("mc"))
            {
                return(revBuffer);
            }

            // Modify the packet?
            Console.WriteLine(from + " ========================================================================================");
            for (int i = 0; i < packets["mc"]; i++)
            {
                BSONObject packet = packets["m" + i] as BSONObject;
                ReadBSON(packet);

                if (packet["ID"].stringValue == "OoIP")
                {
                    PIXEL_IP     = (packet["IP"].stringValue == "prod.gamev70.portalworldsgame.com" ? "3.220.252.91" : packet["IP"].stringValue);
                    packet["IP"] = "prod.gamev70.portalworldsgame.com";
                }
            }

            // Dump the BSON and add padding.
            MemoryStream memoryStream = new MemoryStream();

            using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
            {
                byte[] bsonDump = SimpleBSON.Dump(packets);

                binaryWriter.Write(bsonDump.Length + 4);
                binaryWriter.Write(bsonDump);
            }
            return(memoryStream.ToArray());
        }
Exemplo n.º 8
0
        private void getUsersOnline_Tick(object sender, EventArgs e)
        {
            try
            {
                if (chatbox.Text.Length <= 0)
                {
                    return;
                }
                BSONObject request = new BSONObject();
                request["msg"]  = "get_online";
                request["note"] = "(none)";
                byte[] requestData = SimpleBSON.Dump(request);

                tClient.Client.BeginSend(requestData, 0, requestData.Length, SocketFlags.None, new AsyncCallback(SendCallback), stateObj);
            }
            catch
            {
            }
        }
Exemplo n.º 9
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            // deinitialization might be required here, decide for your self, I get weird service failure errors due to that, too lazy to fix.
            srvRunning    = false;
            clientRunning = false;

            try
            {
                BSONObject bObj = new BSONObject();
                bObj["msg"]  = "quit";
                bObj["note"] = "Goodbye.";
                byte[] data = SimpleBSON.Dump(bObj);

                tClient.Client.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), stateObj.workSocket);
            }
            catch
            {
            }
            Environment.Exit(0);
        }
Exemplo n.º 10
0
        public void WriteAndRead()
        {
            var obj = new BSONObject();

            obj["hello"] = 123;

            obj["where"]          = new BSONObject();
            obj["where"]["Korea"] = "Asia";
            obj["where"]["USA"]   = "America";
            obj["bytes"]          = new byte[41223];

            byte [] buf = SimpleBSON.Dump(obj);
            Console.WriteLine(buf);

            obj = SimpleBSON.Load(buf);

            Console.WriteLine(obj["hello"].int32Value);             // => 123
            Console.WriteLine(obj["where"]["Korea"].stringValue);   // => "Asia"
            Console.WriteLine(obj["where"]["USA"].stringValue);     // => "America"
            Console.WriteLine(obj["bytes"].binaryValue.Length);     // => 128-length bytesbytes
        }