Пример #1
0
        public static void HandleTransfer(LoginConnector 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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
     }
 }
Пример #4
0
 public void SendPong()
 {
     using (var packet = new InterPacket(InterHeader.PONG))
     {
         client.SendPacket(packet);
     }
 }
Пример #5
0
 public static void SendAssigned(WorldConnection wc)
 {
     using (var p = new InterPacket(InterHeader.ASSIGNED))
     {
         wc.SendPacket(p);
     }
 }
Пример #6
0
 public void SendPing()
 {
     Pong = false;
     using (var packet = new InterPacket(InterHeader.PING))
     {
         client.SendPacket(packet);
     }
 }
Пример #7
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);
     }
 }
Пример #8
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);
        }
Пример #9
0
        public void SendData()
        {
            using (var packet = new InterPacket(InterHeader.ASSIGNED))
            {
                packet.WriteStringLen(ConnectionStringbuilder.CreateEntityString(Settings.Instance.Entity));
                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);
            }
        }
Пример #10
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 = "Solar.Zone[" + id + "]";
            Log.WriteLine(LogLevel.Info, "Successfully linked with worldserver. [Zone: {0} | Port: {1}]", id, port);
            ZoneAcceptor.Load();
        }
Пример #11
0
 public static void SendZoneStopped(byte zoneid)
 {
     using (var packet = new InterPacket(InterHeader.ZONECLOSED))
     {
         packet.Write(zoneid);
         foreach (var c in Program.Zones.Values)
             c.SendPacket(packet);
     }
 }
Пример #12
0
 public static void HandleAssigned(LoginConnector lc, InterPacket packet)
 {
     Log.WriteLine(LogLevel.Info, "<3 LoginServer.");
 }
Пример #13
0
 public static void SendZoneStarted(byte zoneid, string ip, ushort port, List<MapInfo> maps)
 {
     using (var packet = new InterPacket(InterHeader.ZONEOPENED))
     {
         packet.WriteByte(zoneid);
         packet.WriteStringLen(ip);
         packet.WriteUShort(port);
         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);
         }
         foreach (var c in Program.Zones.Values)
         {
             if (c.ID != zoneid)
                 c.SendPacket(packet);
         }
     }
 }
Пример #14
0
 public static void SendZoneList(ZoneConnection zc)
 {
     using (var packet = new InterPacket(InterHeader.ZONELIST))
     {
         packet.Write(Program.Zones.Values.Count);
         foreach (var z in Program.Zones.Values)
         {
             packet.Write(z.ID);
             packet.Write(z.IP);
             packet.Write(z.Port);
             packet.WriteInt(z.Maps.Count);
             foreach (var m in z.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);
             }
         }
         zc.SendPacket(packet);
     }
 }
Пример #15
0
 public static void HandleWorldMessage(ZoneConnection zc, InterPacket packet)
 {
     string msg;
     bool wut;
     byte type;
     if (!packet.TryReadString(out msg) || !packet.TryReadByte(out type) || !packet.TryReadBool(out wut))
     {
         return;
     }
     if (wut)
     {
         string to;
         if (!packet.TryReadString(out to))
         {
             return;
         }
         WorldClient client;
         if ((client = ClientManager.Instance.GetClientByCharname(to)) == null)
         {
             Log.WriteLine(LogLevel.Warn, "Tried to send a WorldMessage to a character that is unknown. Charname: {0}", to);
         }
         else
         {
             using (var p = Handler25.CreateWorldMessage((WorldMessageTypes)type, msg))
             {
                 client.SendPacket(p);
             }
         }
     }
     else
     {
         using (var p = Handler25.CreateWorldMessage((WorldMessageTypes)type, msg))
         {
             ClientManager.Instance.SendPacketToAll(p);
         }
     }
 }
 public InterPacketReceivedEventArgs(InterPacket packet, InterClient client)
 {
     this.Packet = packet;
     this.Client = client;
 }
Пример #17
0
 public void SendInterPass(string what)
 {
     InterPacket packet = new InterPacket(InterHeader.AUTH);
     packet.WriteStringLen(what);
     SendPacket(packet);
 }
Пример #18
0
 public static void TransferClient(byte zoneID, int accountID, string userName, string charName, ushort randid, byte admin, string hostIP)
 {
     using (var packet = new InterPacket(InterHeader.CLIENTTRANSFERZONE))
     {
         packet.WriteByte(zoneID);
         packet.WriteInt(accountID);
         packet.WriteStringLen(userName);
         packet.WriteStringLen(charName);
         packet.WriteUShort(randid);
         packet.WriteByte(admin);
         packet.WriteStringLen(hostIP);
         WorldConnector.Instance.SendPacket(packet);
     }
 }
Пример #19
0
 public static void TryAssiging(WorldConnector lc)
 {
     using (var p = new InterPacket(InterHeader.ASSIGN))
     {
         p.WriteStringLen(Settings.Instance.IP);
         lc.SendPacket(p);
     }
 }
Пример #20
0
 public static void HandleZoneClosed(WorldConnector lc, InterPacket packet)
 {
     byte id;
     if (!packet.TryReadByte(out id))
     {
         return;
     }
     ZoneData zd;
     if (Program.Zones.TryRemove(id, out zd))
     {
         Log.WriteLine(LogLevel.Info, "Removed zone {0} from zones (disconnected)", id);
     }
 }
Пример #21
0
 private void SendIVs()
 {
     InterPacket packet = new InterPacket(InterHeader.IVS);
     packet.WriteBytes(mIVSend);
     SendPacket(packet, false);
 }
Пример #22
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();
        }
Пример #23
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);
 }
Пример #24
0
 public static void TryAssiging(LoginConnector lc)
 {
     using (var p = new InterPacket(InterHeader.ASSIGN))
     {
         p.WriteByte(Settings.Instance.ID);
         p.WriteStringLen(Settings.Instance.WorldName);
         p.WriteStringLen(Settings.Instance.IP);
         p.WriteUShort(Settings.Instance.Port);
         lc.SendPacket(p);
     }
 }
Пример #25
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);
     }
 }
Пример #26
0
 public void SendPacket(InterPacket packet)
 {
     if (this.client == null) return;
     this.client.SendPacket(packet);
 }
Пример #27
0
 public void SendTransferClientFromZone(int accountID, string userName, string charName, 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.WriteUShort(randid);
         packet.WriteByte(admin);
         packet.WriteStringLen(hostIP);
         this.SendPacket(packet);
     }
 }
Пример #28
0
        public static void HandleZoneOpened(WorldConnector lc, InterPacket packet)
        {
            byte id;
            string ip;
            ushort port;
            int mapcount;
            if (!packet.TryReadByte(out id) || !packet.TryReadString(out ip) || !packet.TryReadUShort(out port) || !packet.TryReadInt(out mapcount))
            {
                return;
            }

            List<MapInfo> maps = new List<MapInfo>();
            for (int j = 0; j < mapcount; j++)
            {
                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;
                }
                maps.Add(new MapInfo(mapid, shortname, fullname, regenx, regeny, kingdom, viewrange)); ;
            }

            ZoneData zd;
            if (!Program.Zones.TryGetValue(id, out zd))
            {
                zd = new ZoneData();
            }
            zd.ID = id;
            zd.IP = ip;
            zd.Port = port;
            zd.MapsToLoad = maps;
            Program.Zones[id] = zd;
            Log.WriteLine(LogLevel.Info, "Added zone {0} to zonelist. {1}:{2}", zd.ID, zd.IP, zd.Port);
        }