示例#1
0
 public static void SendAssigned(WorldConnection wc)
 {
     using (var p = new InterPacket(InterHeader.ASSIGNED))
     {
         wc.SendPacket(p);
     }
 }
示例#2
0
        public static void Broadcast(WorldConnector pConnector, InterPacket pPacket)
        {
            int packetlenght;
            byte[] packet;
            string charname;
            if (!pPacket.TryReadString(out charname, 16))
                return;

            if (!pPacket.TryReadInt(out packetlenght))
                return;

            if (!pPacket.TryReadBytes(packetlenght, out packet))
                return;

            ZoneClient pClient = ClientManager.Instance.GetClientByCharName(charname);
            if (pClient == null)
                return;
            using (var ipacket = new InterPacket(InterHeader.SendBroiadCastList))
            {
                List<ZoneCharacter> Sender = pClient.Character.Map.GetCharactersBySectors(pClient.Character.MapSector.SurroundingSectors);
                if (Sender.Count == 0)
                    return;
                ipacket.WriteInt(packetlenght);
                ipacket.WriteBytes(packet);
                ipacket.WriteInt(Sender.Count);
                foreach (var character in Sender)
                {
                    ipacket.WriteString(character.Name,16);
                }
                pConnector.SendPacket(ipacket);
            }
        }
示例#3
0
 public void SendPong()
 {
     using (var packet = new InterPacket(InterHeader.Pong))
     {
         client.SendPacket(packet);
     }
 }
示例#4
0
        public static void ChangeZoneBeginn(ZoneConnection zc, InterPacket packet)
        {
            ushort mapid,randomid,port;
            string charname,ip;
            int x,y;
            if(!packet.TryReadUShort(out mapid))
                return;
            if(!packet.TryReadInt(out x))
                return;
            if(!packet.TryReadInt(out y))
                return;
            if(!packet.TryReadString(out charname,16))
                return;
            if(!packet.TryReadString(out ip,16))
                return;
            if(!packet.TryReadUShort(out port))
                return;
            if(!packet.TryReadUShort(out randomid))
                return;

            WorldClient client = ClientManager.Instance.GetClientByCharname(charname);
            if(client == null)
                return;
            int oldmap = client.Character.Character.PositionInfo.Map;
            client.Character.Character.PositionInfo.Map = mapid;
            client.Character.Character.PositionInfo.XPos = x;
            client.Character.Character.PositionInfo.YPos = y;
            Managers.CharacterManager.InvokeChangeMapEvent(client.Character);
            client.Character.ChangeFrendMap(DataProvider.GetMapname(mapid));//setup later to event
        }
示例#5
0
        private void SendIVs()
        {
            InterPacket packet = new InterPacket(InterHeader.IVS);

            packet.WriteBytes(mIVSend);
            SendPacket(packet, false);
        }
示例#6
0
        public void SendInterPass(string what)
        {
            InterPacket packet = new InterPacket(InterHeader.AUTH);

            packet.WriteStringLen(what);
            SendPacket(packet);
        }
示例#7
0
 public static void HandleClientTransferZone(ZoneConnection zc, InterPacket packet)
 {
     byte admin, zoneid;
     int accountid;
     string username, charname, hostip;
     ushort randid;
     if (!packet.TryReadByte(out zoneid) || !packet.TryReadInt(out accountid) || !packet.TryReadString(out username) ||
         !packet.TryReadString(out charname) || !packet.TryReadUShort(out randid) || !packet.TryReadByte(out admin) ||
         !packet.TryReadString(out hostip))
     {
         return;
     }
     if (Program.Zones.ContainsKey(zoneid))
     {
         ZoneConnection z;
         if (Program.Zones.TryGetValue(zoneid, out z))
         {
             z.SendTransferClientFromZone(accountid, username, charname, randid, admin, hostip);
         }
     }
     else
     {
         Log.WriteLine(LogLevel.Warn, "Uh oh, Zone {0} tried to transfer {1} to zone {1} D:", zc.ID, charname, zoneid);
     }
 }
示例#8
0
 public void Broadcast(InterPacket pPacket)
 {
     foreach (var zone in Program.Zones.Values)
     {
         zone.SendPacket(pPacket);
     }
 }
示例#9
0
 public void SendPacket(InterPacket pPacket, bool crypto = true)
 {
     byte[] data = new byte[pPacket.Length + 4];
     Buffer.BlockCopy(crypto ? InterCrypto.EncryptData(mIVSend, pPacket.ToArray()) : pPacket.ToArray(), 0, data, 4, pPacket.Length);
     Buffer.BlockCopy(BitConverter.GetBytes((int)pPacket.Length), 0, data, 0, 4);
     Send(data);
 }
示例#10
0
        public static void On_WorldClient_AcademyMemberLeft(WorldConnector pConnector, InterPacket pPacket)
        {
            int guildID, characterID;
            if (!pPacket.TryReadInt(out guildID)
                || !pPacket.TryReadInt(out characterID))
            {
                return;
            }

            Guild guild;
            if (GuildManager.GetGuildByID(guildID, out guild))
            {
                GuildAcademyMember member;
                if (guild.Academy.GetMember(characterID, out member))
                {
                    guild.Academy.Members.Remove(member);
                    member.Dispose();

                    ZoneCharacter character;
                    if (CharacterManager.GetLoggedInCharacter(characterID, out character))
                    {
                        character.Guild = null;
                        character.GuildAcademy = null;
                        character.GuildAcademyMember = null;

                        GuildManager.RemoveGuildBuff(character);
                    }
                }
            }
        }
示例#11
0
        public static void On_WorldClient_AcademyMemberJoined(WorldConnector pConnector, InterPacket pPacket)
        {
            int guildID, characterID;
            DateTime registerDate;
            if (!pPacket.TryReadInt(out guildID)
                || !pPacket.TryReadInt(out characterID)
                || !pPacket.TryReadDateTime(out registerDate))
            {
                return;
            }

            Guild guild;
            if (GuildManager.GetGuildByID(guildID, out guild))
            {
                var member = new GuildAcademyMember(guild.Academy, characterID, GuildAcademyRank.Member, registerDate)
                {
                    IsOnline = true,
                };
                guild.Academy.Members.Add(member);

                ZoneCharacter character;
                if (CharacterManager.GetLoggedInCharacter(characterID, out character))
                {
                    member.Character = character;

                    character.Guild = guild;
                    character.GuildAcademy = guild.Academy;
                    character.GuildAcademyMember = member;

                    GuildManager.SetGuildBuff(character);
                }
            }
        }
示例#12
0
        public static void HandleTransfer(WorldConnector lc, InterPacket packet)
        {
            byte v;
            if (!packet.TryReadByte(out v))
            {
                return;
            }

            if (v == 0)
            {
                byte admin;
                int accountid;
                string username, hash, hostip;
                if (!packet.TryReadInt(out accountid) || !packet.TryReadString(out username) || !packet.TryReadString(out hash) || !packet.TryReadByte(out admin) || !packet.TryReadString(out hostip))
                {
                    return;
                }
                ClientTransfer ct = new ClientTransfer(accountid, username, admin, hostip, hash);
                ClientManager.Instance.AddTransfer(ct);
            }
            else if (v == 1)
            {
                byte admin;
                int accountid;
                string username, charname, hostip;
                ushort randid;
                if (!packet.TryReadInt(out accountid) || !packet.TryReadString(out username) || !packet.TryReadString(out charname) ||
                    !packet.TryReadUShort(out randid) || !packet.TryReadByte(out admin) || !packet.TryReadString(out hostip))
                {
                    return;
                }
                ClientTransfer ct = new ClientTransfer(accountid, username, charname, randid, admin, hostip);
                ClientManager.Instance.AddTransfer(ct);
            }
        }
示例#13
0
        public static void HandleServerAssignement(WorldConnection wc, InterPacket packet)
        {
            byte wid;
            string name, ip;
            ushort port;
            if (!packet.TryReadByte(out wid) || !packet.TryReadString(out name) || !packet.TryReadString(out ip) || !packet.TryReadUShort(out port))
            {
                Log.WriteLine(LogLevel.Error, "Could not read World ID in inter server packet.");
                wc.Disconnect();
                return;
            }

            if (WorldManager.Instance.Worlds.ContainsKey(wid))
            {
                Log.WriteLine(LogLevel.Error, "Already loaded this world?");
                wc.Disconnect();
                return;
            }

            wc.Name = name;
            wc.ID = wid;
            wc.IP = ip;
            wc.Port = port;
            wc.IsAWorld = true;

            if (WorldManager.Instance.Worlds.TryAdd(wc.ID, wc))
            {
                Log.WriteLine(LogLevel.Info, "Assigned world {0}!", wc.ID);
                SendAssigned(wc);
            }
            else
            {
                Log.WriteLine(LogLevel.Error, "Couldn't assign world {0}..", wc.ID);
            }
        }
示例#14
0
 public static void BackTo(ZoneClient client, Packet packet)
 {
     using(var iacket = new InterPacket(InterHeader.ClientDisconect))
     {
         iacket.WriteString(client.Character.Character.Name, 16);
         InterServer.WorldConnector.Instance.SendPacket(iacket);
     }
 }
示例#15
0
 public static void Banaccount(WorldConnection wc, InterPacket packet)
 {
     int acountid;
     if (packet.TryReadInt(out acountid))
     {
         Program.DatabaseManager.GetClient().ExecuteQuery("UPDATE Accounts Set Blocked='1' WHERE ID="+acountid+"");
     }
 }
示例#16
0
 public void SendPing()
 {
     Pong = false;
     using (var packet = new InterPacket(InterHeader.PING))
     {
         client.SendPacket(packet);
     }
 }
示例#17
0
 public static void AddPartyMember(WorldConnector lc, InterPacket packet)
 {
     long groupId = 0;
     string charName = "";
     if (!packet.TryReadLong(out groupId) &&
         !packet.TryReadString(out charName, 16))
     {
         throw new InvalidPacketException();
     }
     GroupManager.Instance.AddMemberToGroup(groupId, charName);
 }
示例#18
0
        public static void RemoveBuff(AbStateInfo AbState, params WorldCharacter[] Receiver)
        {
            using (var packet = new InterPacket(InterHeader.ZONE_CharacterRemoveBuff))
            {
                packet.WriteUShort(AbState.ID);

                packet.WriteInt(Receiver.Length);
                Array.ForEach(Receiver, ch => packet.WriteInt(ch.ID));

                ZoneManager.Instance.Broadcast(packet);
            }
        }
示例#19
0
 public void SendTransferClientFromWorld(int accountID, string userName, byte admin, string hostIP, string hash)
 {
     using (var packet = new InterPacket(InterHeader.CLIENTTRANSFER))
     {
         packet.WriteByte(0);
         packet.WriteInt(accountID);
         packet.WriteStringLen(userName);
         packet.WriteStringLen(hash);
         packet.WriteByte(admin);
         packet.WriteStringLen(hostIP);
         this.SendPacket(packet);
     }
 }
示例#20
0
        public static void DisconnectFromzoneserver(ZoneConnection zc, InterPacket packet)
        {
            string charname;
            if (packet.TryReadString(out charname,16))
            {
              WorldClient client =  ClientManager.Instance.GetClientByCharname(charname);
              if (client == null)
                  return;

              client.Character.Loggeout(client);
              ClientManager.Instance.RemoveClient(client);
            }
        }
示例#21
0
 public void SendTransferClientFromZone(int accountID, string userName, string charName,int CharID, ushort randid, byte admin, string hostIP)
 {
     using (var packet = new InterPacket(InterHeader.Clienttransfer))
     {
         packet.WriteByte(1);
         packet.WriteInt(accountID);
         packet.WriteStringLen(userName);
         packet.WriteStringLen(charName);
         packet.WriteInt(CharID);
         packet.WriteUShort(randid);
         packet.WriteByte(admin);
         packet.WriteStringLen(hostIP);
         this.SendPacket(packet);
     }
 }
示例#22
0
        public static void HandleAssigning(ZoneConnection lc, InterPacket packet)
        {
            string ip;
            if (!packet.TryReadString(out ip))
            {
                return;
            }

            lc.IP = ip;

            // make idlist
            InterHandler.SendZoneStarted(lc.ID, lc.IP, lc.Port, lc.Maps);
            InterHandler.SendZoneList(lc);
            Log.WriteLine(LogLevel.Info, "Zone {0} listens @ {1}:{2}", lc.ID, lc.IP, lc.Port);
        }
示例#23
0
        public static void FunctionGetCharacterOnline(ZoneConnection pConnection, InterPacket pPacket)
        {
            long id;
            string charName;

            if(!pPacket.TryReadLong(out id) ||!pPacket.TryReadString(out charName, 16))
                throw new InvalidPacketException();

            bool isOnline = ClientManager.Instance.IsOnline(charName);
            using (InterPacket packet = new InterPacket(InterHeader.FunctionAnswer))
            {
                packet.WriteLong(id);
                packet.WriteBool(isOnline);
                pConnection.SendPacket(packet);
            }
        }
示例#24
0
 public static void BanAccount(ZoneConnection zc, InterPacket packet)
 {
     string playername;
       if (packet.TryReadString(out playername, 16))
       {
           WorldClient bannclient = ClientManager.Instance.GetClientByCharname(playername);
           if (bannclient != null)
           {
               using (var p = new InterPacket(InterHeader.BanAccount))
               {
                   p.WriteInt(bannclient.AccountID);
                   LoginConnector.Instance.SendPacket(p);
               }
               bannclient.Disconnect();
           }
       }
 }
示例#25
0
        public static void AddRewardItem(WorldConnector pConnector, InterPacket pPacket)
        {
            byte count;
            ushort ItemID;
            string Charname;
            if (!pPacket.TryReadUShort(out ItemID))
                return;

            if (!pPacket.TryReadByte(out count))
                return;

            if(!pPacket.TryReadString(out Charname,16))
                return;

             ZoneClient pClient =  ClientManager.Instance.GetClientByName(Charname);
            if(pClient == null)
                return;

            pClient.Character.GiveMasterRewardItem(ItemID, count);
        }
示例#26
0
        public static void On_WorldClient_AcademyBuffUpdate(WorldConnector pConnector, InterPacket pPacket)
        {
            int guildID;
            DateTime updateTime;
            double keepTime;
            if (!pPacket.TryReadInt(out guildID)
                || !pPacket.TryReadDateTime(out updateTime)
                || !pPacket.TryReadDouble(out keepTime))
            {
                //Client.Dispose();
                return;
            }

            Guild guild;
            if (GuildManager.GetGuildByID(guildID, out guild))
            {
                guild.Academy.GuildBuffUpdateTime = updateTime;
                guild.Academy.GuildBuffKeepTime = TimeSpan.FromSeconds(keepTime);
            }
        }
示例#27
0
        public void SendData()
        {
            using (var packet = new InterPacket(InterHeader.Assigned))
            {
                packet.WriteByte(ID);
                packet.WriteStringLen(String.Format("{0}-{1}", Settings.Instance.GameServiceUri, ID));
                packet.WriteUShort((ushort)(Settings.Instance.ZoneBasePort + ID));

                packet.WriteInt(Maps.Count);
                foreach (var m in Maps)
                {
                    packet.WriteUShort(m.ID);
                    packet.WriteStringLen(m.ShortName);
                    packet.WriteStringLen(m.FullName);
                    packet.WriteInt(m.RegenX);
                    packet.WriteInt(m.RegenY);
                    packet.WriteByte(m.Kingdom);
                    packet.WriteUShort(m.ViewRange);
                }
                this.SendPacket(packet);
            }
        }
示例#28
0
        public static void HandleAssigned(WorldConnector lc, InterPacket packet)
        {
            string entity, name;
            byte id;
            ushort port;
            int mapidcout;
            if (!packet.TryReadString(out entity) || !packet.TryReadByte(out id) || !packet.TryReadString(out name) ||
                !packet.TryReadUShort(out port) || !packet.TryReadInt(out mapidcout))
            {
                return;
            }

            Program.serviceInfo = new ZoneData
            {
                EntityString = entity,
                ID = id,
                Port = port,
                MapsToLoad = new List<FiestaLib.Data.MapInfo>()
            };

            for (int i = 0; i < mapidcout; i++)
            {
                ushort mapid, viewrange;
                string shortname, fullname;
                int regenx, regeny;
                byte kingdom;
                if (!packet.TryReadUShort(out mapid) || !packet.TryReadString(out shortname) || !packet.TryReadString(out fullname) || !packet.TryReadInt(out regenx) || !packet.TryReadInt(out regeny) || !packet.TryReadByte(out kingdom) || !packet.TryReadUShort(out viewrange))
                {
                    break;
                }
                Program.serviceInfo.MapsToLoad.Add(new MapInfo(mapid, shortname, fullname, regenx, regeny, kingdom, viewrange)); ;
            }

            Console.Title = "Zepheus.Zone[" + id + "]";
            Log.WriteLine(LogLevel.Info, "Successfully linked with worldserver. [Zone: {0} | Port: {1}]", id, port);
            ZoneAcceptor.Load();
        }
示例#29
0
 public static void UpdateMoneyWorld(long Money,string charname)
 {
     using (var packet = new InterPacket(InterHeader.UpdateMoney))
     {
         packet.WriteString(charname, 16);
         packet.WriteLong(Money);
         WorldConnector.Instance.SendPacket(packet);
     }
 }
示例#30
0
 public static void TryAssiging(WorldConnector lc)
 {
     using (var p = new InterPacket(InterHeader.Assign))
     {
         p.WriteStringLen(Settings.Instance.IP);
         lc.SendPacket(p);
     }
 }
示例#31
0
 public static void TransferClient(byte zoneID,ushort mapid, int accountID, string userName,int CharID, string charName, ushort randid, byte admin, string hostIP)
 {
     using (var packet = new InterPacket(InterHeader.Clienttransferzone))
     {
         packet.WriteByte(zoneID);
         packet.WriteInt(accountID);
         packet.WriteUShort(mapid);
         packet.WriteStringLen(userName);
         packet.WriteStringLen(charName);
         packet.WriteInt(CharID);
         packet.WriteUShort(randid);
         packet.WriteByte(admin);
         packet.WriteStringLen(hostIP);
         WorldConnector.Instance.SendPacket(packet);
     }
 }
示例#32
0
 public static void SendWorldMessage(WorldMessageTypes type, string message, string to = "")
 {
     using (var packet = new InterPacket(InterHeader.Worldmsg))
     {
         packet.WriteStringLen(message);
         packet.WriteByte((byte)type);
         packet.WriteBool(to != "");
         if (to != "")
         {
             packet.WriteStringLen(to);
         }
         WorldConnector.Instance.SendPacket(packet);
     }
 }
示例#33
0
        private void EndReceive(object sender, SocketAsyncEventArgs pArguments)
        {
            if (mDisconnected != 0)
            {
                return;
            }
            if (pArguments.BytesTransferred <= 0)
            {
                Disconnect();
                return;
            }
            mReceiveLength += pArguments.BytesTransferred;

            if (mReceivingPacketLength == mReceiveLength)
            {
                if (mHeader) //parse headers
                {
                    mReceivingPacketLength = BitConverter.ToInt32(mReceiveBuffer, 0);
                    mReceiveLength         = 0;
                    mReceiveStart          = 0;
                    mHeader = false;
                    // mReceiveBuffer = new byte[mReceivingPacketLength];
                }
                else
                { //parse packets
                    byte[] packetData = new byte[mReceivingPacketLength];
                    Buffer.BlockCopy(mReceiveBuffer, 0, packetData, 0, mReceivingPacketLength);
                    if (!mIVs)
                    {
                        InterPacket packet = new InterPacket(packetData);
                        if (packet.OpCode == InterHeader.IVS)
                        {
                            Log.WriteLine(LogLevel.Info, "IV data received");
                            packet.ReadBytes(mIVRecv);
                            mIVs = true;
                        }
                        else
                        {
                            Log.WriteLine(LogLevel.Info, "Got wrong packet.");
                            Disconnect();
                        }
                    }
                    else
                    {
                        packetData = InterCrypto.DecryptData(mIVRecv, packetData);
                        if (OnPacket != null)
                        {
                            InterPacket packet = new InterPacket(packetData);
                            this.OnPacket(this, new InterPacketReceivedEventArgs(packet, this));
                        }
                    }
                    //we reset this packet
                    mReceivingPacketLength = 4;
                    mReceiveLength         = 0;
                    mReceiveStart          = 0;
                    mHeader = true;
                    // mReceiveBuffer = new byte[4];
                }
            }
            else
            {
                mReceiveStart += mReceivingPacketLength;
            }

            BeginReceive();
            pArguments.Dispose();
        }
示例#34
0
 public static void ChangeMoney(WorldConnector pConnector, InterPacket pPacket)
 {
     int CharID;
     long NewMoney;
     if (!pPacket.TryReadInt(out CharID))
         return;
     if (!pPacket.TryReadLong(out NewMoney))
         return;
     ZoneClient pClient = ClientManager.Instance.GetClientByCharID(CharID);
     if (pClient == null)
         return;
     pClient.Character.ChangeMoney(NewMoney);
 }
 public InterPacketReceivedEventArgs(InterPacket packet, InterClient client)
 {
     this.Packet = packet;
     this.Client = client;
 }