示例#1
0
        public static object Deserialize(byte[] data)
        {
            CustomObject customObject = new CustomObject();

            GetFromBinary(data, customObject);
            return(customObject);
        }
示例#2
0
        public static object Deserialize(byte[] data)
        {
            ListPartitioningInfo customObject = new ListPartitioningInfo();

            CustomObject.GetFromBinary(data, customObject);
            return(customObject);
        }
示例#3
0
        public static object Deserialize(byte[] data)
        {
            MonsterInfo customObject = new MonsterInfo();

            CustomObject.GetFromBinary(data, customObject);
            return(customObject);
        }
示例#4
0
        public static object Deserialize(byte[] data)
        {
            PlayerPos customObject = new PlayerPos();

            CustomObject.GetFromBinary(data, customObject);
            return(customObject);
        }
示例#5
0
        public static object Deserialize(byte[] data)
        {
            AccountdDetails customObject = new AccountdDetails();

            CustomObject.GetFromBinary(data, customObject);
            return(customObject);
        }
示例#6
0
        protected static void GetFromBinary(int _index, CustomObject _object, BinaryReader br)
        {
            Console.Write("\n" + _object._fields[_index].Name);
            switch (_object._types[_index])
            {
            case DataTypes.BYTE:
                _object._fields[_index].SetValue(_object, br.ReadByte());
                break;

            case DataTypes.BOOL:
                _object._fields[_index].SetValue(_object, br.ReadBoolean());
                break;

            case DataTypes.SHORT:
                _object._fields[_index].SetValue(_object, br.ReadInt16());

                break;

            case DataTypes.INT:
                _object._fields[_index].SetValue(_object, br.ReadInt32());

                break;

            case DataTypes.LONG:
                _object._fields[_index].SetValue(_object, br.ReadInt64());

                break;

            case DataTypes.FLOAT:
                _object._fields[_index].SetValue(_object, br.ReadSingle());

                break;

            case DataTypes.DOUBLE:
                _object._fields[_index].SetValue(_object, br.ReadDouble());

                break;

            case DataTypes.STRING:
                _object._fields[_index].SetValue(_object, br.ReadString());

                break;

            case DataTypes.LIST:
                List <int> list = new List <int>();
                int        size = br.ReadInt32();
                for (int i = 0; i < size; ++i)
                {
                    list.Add(br.ReadInt32());
                }

                _object._fields[_index].SetValue(_object, list);

                break;
            }
        }
示例#7
0
        protected static void GetFromBinary(byte[] _bytes, CustomObject _object)
        {
            _object.Init();

            using (var s = new MemoryStream(_bytes))
            {
                using (var br = new BinaryReader(s))
                {
                    for (int i = 0; i < _object._fields.Count; ++i)
                    {
                        GetFromBinary(i, _object, br);
                    }
                }
            }
        }
        //Byte-Array-based Decoding
        //Byte-Array-based Decoding
        /// <summary>
        /// Decoding for CustomObject - Decoding format: TargetReceiverName, ObjectName, ObjectHealth, ObjectPosX, ObjectPosY, ObjectPosZ, ObjectRotX, ObjectRotY, ObjectRotZ, ObjectRotW
        /// </summary>
        public object DecodeCustomObject(byte[] bytes)
        {
            CustomObject customObject = new CustomObject();

            using (var s = new MemoryStream(bytes))
            {
                using (var br = new BinaryReader(s))
                {
                    customObject.SetPacketTarget(br.ReadString());
                    customObject.SetObjectName(br.ReadString());
                    customObject.SetHealth(br.ReadInt32());
                    customObject.SetPos(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                    customObject.SetRot(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());

                    return(customObject);
                }
            }
        }
示例#9
0
        public void Update(object _plugin)
        {
            RaiseEventTestPlugin RETP = (RaiseEventTestPlugin)_plugin;

            isAlive        = true;
            m_statemanager = new StateManager <STATE>();
            m_statemanager.CurrstateReqUpdate = true;
            m_statemanager.AddUpdateFunction(STATE.IDLE, Idle);
            m_statemanager.AddUpdateFunction(STATE.CHASE, Chase);
            m_statemanager.AddUpdateFunction(STATE.ROAM, Roam);
            m_statemanager.AddUpdateFunction(STATE.ATTACK, Attack);

            m_statemanager.Currstate = m_statemanager.Prevstate = STATE.IDLE;
            while (isAlive)
            {
                //run AI Code
                lock (_info)
                {
                    m_statemanager.Update();
                    RETP.SendMessage(103, MonsterInfo.Serialize(_info));
                    if (_newinfo != null)
                    {
                        lock (_newinfo)
                        {
                            _info.playerposx = _newinfo.playerposx;
                            _info.playerposz = _newinfo.playerposz;
                            _info.playerhp   = _newinfo.playerhp;
                            _info.hp         = _newinfo.hp;
                            _newinfo         = null;
                        }
                    }
                }
                CustomObject co = new CustomObject();
                co.Init();
                co.message = "Update Success " + m_statemanager.Currstate.ToString();
                RETP.SendMessage(169,
                                 CustomObject.Serialize(co)
                                 );
                System.Threading.Thread.Sleep(500);
            }
        }
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            try
            {
                base.OnRaiseEvent(info);
            }
            catch (Exception ex)
            {
                this.PluginHost.BroadcastErrorInfoEvent(ex.ToString(), info);
                return;
            }

            string stringData = "";

            try
            {
                stringData = Encoding.Default.GetString((byte[])info.Request.Data);
                SenderName = PacketDecoder.Instance.GetStringFromString(stringData, "Name");
            }
            catch (Exception ex)
            {
                //this.PluginHost.BroadcastErrorInfoEvent(ex.ToString(), info);
                Console.WriteLine(ex.ToString());
            }

            CustomObject packetData = null;

            try
            {
                packetData = (CustomObject)PacketDecoder.Instance.DecodeCustomObject((byte[])info.Request.Data);
            }
            catch (Exception ex)
            {
                //this.PluginHost.BroadcastErrorInfoEvent(ex.ToString(), info);
                Console.WriteLine(ex.ToString());
            }

            ///ASSIGNMENT 2 STUFF
            ///ASSIGNMENT 2 STUFF
            ///ASSIGNMENT 2 STUFF
            //TEST PACKET
            if (info.Request.EvCode == (byte)EVENT_CODES.TEST_PING)
            {
                SendListOfPlayers(info);
            }

            //Client asking for all AIs
            if (info.Request.EvCode == (byte)EVENT_CODES.EV_INITAI)
            {
                if (packetData != null)
                {
                    //Make sure AIManager thread is fully initialized and running
                    do
                    {
                        Thread.Sleep(100);
                    }while (AIManager.Instance == null);

                    //Iterate and send AI to the requesting client
                    foreach (AI enemy in AIManager.Instance.GetAIList())
                    {
                        //Set packetTarget to be the requesting client name so ONLY the requesting client will open
                        //This is to prevent duplicate AI from spawning on other clients when a new client joins the server
                        enemy.SetPacketTarget(packetData.GetPacketTarget());
                        this.PluginHost.BroadcastEvent(target: ReciverGroup.All, senderActor: 0, targetGroup: 0, evCode: (byte)EVENT_CODES.EV_SPAWNAI, data: new Dictionary <byte, object>()
                        {
                            { (byte)245, enemy }
                        }, cacheOp: 0);
                    }
                }
            }

            //Client updating position within server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_UPDATEPLAYERPOS)
            {
                foreach (Player connectedPlayer in ConnectedPlayers)
                {
                    if (connectedPlayer.GetObjectName() == packetData.GetObjectName())
                    {
                        connectedPlayer.SetPos(packetData.GetPos());
                        return;
                    }
                }
            }

            //Client asking for List of all connected clients
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_LISTALLUSERS)
            {
                SendListOfPlayers(info);
            }

            //User joining server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_USERJOINING)
            {
                UserJoined(info);
            }
            //User leaving server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_USERLEAVING)
            {
                UserLeft(info);
            }

            ///ASSIGNMENT 1 STUFF
            ///ASSIGNMENT 1 STUFF
            ///ASSIGNMENT 1 STUFF

            //Search Users Data from Database from Server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_SEARCHDB)
            {
                SearchUsersDatabase(info);
            }
            //Insert Users Data into Database from Server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_INSERTDB)
            {
                InsertUsersDatabase(info);
            }
            //Update Users Data in Database from Server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_UPDATEDB)
            {
                UpdateUsersDatabase(info);
            }

            //Add Friend in Database from Server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_ADD_FRIEND)
            {
                InsertFriendsDatabase(info);
            }
            //Remove Friend in Database from Server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_REMOVE_FRIEND)
            {
                DeleteFriendsDatabase(info);
            }
            //Accept Friend in Database from Server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_ACCEPT_FRIEND)
            {
                UpdateFriendsDatabase(info);
            }
            //Decline Friend in Database from Server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_DECLINE_FRIEND)
            {
                UpdateFriendsDatabase(info);
            }
            //List Friend in Database from Server
            else if (info.Request.EvCode == (byte)EVENT_CODES.EV_LIST_FRIEND)
            {
                SearchFriendsDatabase(info);
            }
        }
示例#11
0
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            try
            {
                base.OnRaiseEvent(info);
            }
            catch (Exception e)
            {
                this.PluginHost.BroadcastErrorInfoEvent(e.ToString(), info);
                return;
            }
            switch (info.Request.EvCode)
            {
            case 1:
            {
                //string RecvdMessage = Encoding.Default.GetString((byte[])info.Request.Data);
                //string PlayerName = PackageDecoder.GetValue(RecvdMessage, "PlayerName");
                //string Password = PackageDecoder.GetValue(RecvdMessage, "Password");

                AccountdDetails ad         = (AccountdDetails)AccountdDetails.Deserialize((byte[])info.Request.Data);
                string          PlayerName = ad.userid;
                string          Password   = ad.pw;

                CustomObject ret = new CustomObject();
                ret.Init();
                ret.message = "WELCOME";

                this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>()
                    {
                        { (byte)245, CustomObject.Serialize(ret) }
                    }, evCode: info.Request.EvCode, cacheOp: 0);

                int usernameexists = Convert.ToInt32(connector.ConnectAndRunScalar("SELECT COUNT(accountdb.account_name) FROM accountdb WHERE account_name = '" + PlayerName + "'"));
                if (Convert.ToInt32(usernameexists) == 0)
                {
                    int rowsaffected = connector.ConnectAndRunNonQuery("INSERT INTO accountdb (account_name, password, date_created) VALUES('" + PlayerName + "', '" + Password + "', now())");
                    if (rowsaffected == 1)
                    {
                        ret.message = "SIGNUP SUCCESS";
                        this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>()
                            {
                                { (byte)245, CustomObject.Serialize(ret) }
                            }, evCode: info.Request.EvCode, cacheOp: 0);
                    }
                }
                else
                {
                    string olwpw = Convert.ToString(connector.ConnectAndRunScalar("SELECT accountdb.password FROM accountdb WHERE accountdb.account_name = '" + PlayerName + "'"));
                    if (Password != olwpw)
                    {
                        ret.message = "NOT VALID";

                        this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>()
                            {
                                { (byte)245, CustomObject.Serialize(ret) }
                            }, evCode: (byte)(69), cacheOp: 0);
                        return;
                    }
                }
                ret.message = "LOGIN SUCESS";

                this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>()
                    {
                        { (byte)245, CustomObject.Serialize(ret) }
                    }, evCode: (byte)(5), cacheOp: 0);

                break;
            }

            case 2:
            {
                PlayerPos pp = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data);

                string RecvdMessage = Encoding.Default.GetString((byte[])info.Request.Data);
                string PlayerName   = pp.userid;                 //PackageDecoder.GetValue(RecvdMessage, "PlayerName");
                string posx         = Convert.ToString(pp.posx); //PackageDecoder.GetValue(RecvdMessage, "posx");
                string posy         = Convert.ToString(pp.posy); //PackageDecoder.GetValue(RecvdMessage, "posy");
                string posz         = Convert.ToString(pp.posz); //PackageDecoder.GetValue(RecvdMessage, "posz");
                connector.ConnectAndRunNonQuery("UPDATE accountdb SET posx = " + posx + ",posy=" + posy + ",posz=" + posz + " WHERE account_name = '" + PlayerName + "'");

                break;
            }

            case 3:
            {
                PlayerPos oldpp      = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data);
                string    PlayerName = oldpp.userid;
                PlayerPos pp         = new PlayerPos();
                pp.Init();
                pp.userid = PackageDecoder.GetValue(PlayerName, "PlayerName");

                pp.posx = (int)connector.ConnectAndRunScalar("Select posx from accountdb where account_name = '" + PlayerName + "'");
                pp.posy = (int)connector.ConnectAndRunScalar("Select posy from accountdb where account_name = '" + PlayerName + "'");
                pp.posz = (int)connector.ConnectAndRunScalar("Select posz from accountdb where account_name = '" + PlayerName + "'");
                this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>()
                    {
                        { (byte)245, PlayerPos.Serialize(pp) }
                    }, evCode: (byte)(3), cacheOp: 0);
                break;
            }

            case 6:
            {
                PlayerPos pp         = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data);
                string    PlayerName = pp.userid;
                string    Guild      = pp.guild;
                connector.ConnectAndRunNonQuery("UPDATE accountdb SET guild = '" + Guild + "' WHERE account_name = '" + PlayerName + "'");
                break;
            }

            case 7:
            {
                PlayerPos pp         = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data);
                string    PlayerName = pp.userid;
                pp.guild = Convert.ToString(connector.ConnectAndRunScalar("SELECT guild FROM accountdb WHERE account_name = '" + PlayerName + "'"));
                this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>()
                    {
                        { (byte)245, PlayerPos.Serialize(pp) }
                    }, evCode: (byte)(7), cacheOp: 0);

                break;
            }

            case 99:
            {
                AccountdDetails ad         = (AccountdDetails)AccountdDetails.Deserialize((byte[])info.Request.Data);
                string          PlayerName = ad.userid;
                string          Password   = ad.pw;

                connector.ConnectAndRunNonQuery("UPDATE accountdb SET password = '******' WHERE account_name = '" + PlayerName + "'");

                break;
            }

            case 101:
            {
                MonsterInfo mi = (MonsterInfo)MonsterInfo.Deserialize((byte[])info.Request.Data);
                AI          ai = new TestPlugin.AI();
                ai._info = mi;
                ailist.Add(ai);

                multithreadmanager.AddThread(ai._info.name, new System.Threading.ParameterizedThreadStart(ai.Update), this);
                multithreadmanager.StartThread(ai._info.name);

                this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr,
                                               senderActor: 0,
                                               targetGroup: 0,
                                               data: new Dictionary <byte, object>()
                    {
                        { (byte)245, MonsterInfo.Serialize(mi) }
                    },
                                               evCode: (byte)(102),
                                               cacheOp: 0);

                break;
            }

            case 103:
            {
                PlayerPos mi = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data);

                this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr,
                                               senderActor: 0,
                                               targetGroup: 0,
                                               data: new Dictionary <byte, object>()
                    {
                        { (byte)245, PlayerPos.Serialize(mi) }
                    },
                                               evCode: (byte)(104),
                                               cacheOp: 0);

                break;
            }

            case 150:
            {
                PlayerPos        mi = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data);
                PartitioningInfo pi = new PartitioningInfo();
                pi.Init();
                pi.objname  = mi.userid;
                pi.currtile = MapPartitioningButNotPartitioningIsJustSplittingUpTheMap.ReturnTileViaPos(mi.posx, mi.posz);
                this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr,
                                               senderActor: 0,
                                               targetGroup: 0,
                                               data: new Dictionary <byte, object>()
                    {
                        { (byte)245, PartitioningInfo.Serialize(pi) }
                    },
                                               evCode: info.Request.EvCode,
                                               cacheOp: 0);
                break;
            }

            case 151:
            {
                PlayerPos            mi = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data);
                ListPartitioningInfo pi = new ListPartitioningInfo();
                pi.Init();
                pi.playerposx = mi.posx;
                pi.playerposz = mi.posz;

                pi.objname    = mi.userid;
                pi.currtile   = MapPartitioningButNotPartitioningIsJustSplittingUpTheMap.ReturnTileViaPos(mi.posx, mi.posz);
                pi._multitile = MapPartitioningButNotPartitioningIsJustSplittingUpTheMap.ReturnSurroundingTilesViaCurrentTile(pi.currtile);
                this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr,
                                               senderActor: 0,
                                               targetGroup: 0,
                                               data: new Dictionary <byte, object>()
                    {
                        { (byte)245, ListPartitioningInfo.Serialize(pi) }
                    },
                                               evCode: info.Request.EvCode,
                                               cacheOp: 0);
                break;
            }

            case 180:
            {
                MonsterInfo mi      = (MonsterInfo)MonsterInfo.Deserialize((byte[])info.Request.Data);
                AI          updater = ailist.Find(x => x._info.name == mi.name);
                updater._newinfo = mi;

                break;
            }
            }
        }