예제 #1
0
        public SilkroadTunnel(SilkroadProxy silkroadProxy, List<SilkroadTunnel> tunnels, MainForm mainForm)
        {
            _remoteIP = "123.30.200.6";
            _remotePort = 15779;

            _silkroadProxy = silkroadProxy;

            _localContext = new Context();
            _localContext.MySecurity.GenerateSecurity(true, true, true);

            _remoteContext = new Context();

            _localContext.MyRelaySecurity = _remoteContext.MySecurity;
            _remoteContext.MyRelaySecurity = _localContext.MySecurity;

            _contexts = new List<Context>();
            _contexts.Add(_localContext);
            _contexts.Add(_remoteContext);

            _tunnels = tunnels;

            _mainForm = mainForm;

            if (_mainForm != null)
            {
                _charracter = new Charracter(_mainForm);
            }
        }
예제 #2
0
 private bool ClientPacketHandler(Context context, Packet packet)
 {
     bool retval = false;
     switch (packet.Opcode)
     {
         case 0x7001:
             {
                 string charname = packet.ReadAscii();
                 _mainForm.UpdateCharName(charname);
                 _charracter.CharName = charname;
             }
             break;
         default:
             break;
     }
     return retval;
 }
예제 #3
0
        private bool ServerPacketHandler(Context context, Packet packet)
        {
            bool retval = false;
            switch (packet.Opcode)
            {
                case 0x303D:
                    {
                        packet.SeekRead(24, SeekOrigin.Begin);
                        uint maxHP = packet.ReadUInt32();
                        uint maxMP = packet.ReadUInt32();
                        _charracter.MaxHP = maxHP;
                        _charracter.MaxMP = maxMP;
                        if (_charracter.CurrentHP > 0)
                        {
                            _mainForm.UpdateProgressBarValue(_charracter.MaxHP, _charracter.MaxHP, _charracter.MaxMP, _charracter.MaxMP);
                        }

                    }
                    break;
                case 0x3020:
                    {
                        _charracter.Id = packet.ReadUInt32();
                        Packet packet3013 = _charracter.Opcode3013;
                        string id = BitConverter.ToString(BitConverter.GetBytes(_charracter.Id)).Replace("-", "");
                        string tempPacket = BitConverter.ToString(packet3013.GetBytes()).Replace("-", "");
                        int index = tempPacket.IndexOf(id, 0);

                        if (index > 0)
                        {
                            float X = 0, Y = 0;
                            byte XX = 0, YY = 0;
                            index = index / 2 + 4;
                            packet3013.SeekRead(index, SeekOrigin.Begin);
                            ushort zonetype = packet3013.ReadUInt16();
                            XX = BitConverter.GetBytes(zonetype)[0];
                            YY = BitConverter.GetBytes(zonetype)[1];
                            if (zonetype >= 32769 && zonetype <= 32775)
                            {
                                X = packet3013.ReadSingle();
                                packet3013.SeekRead(index + 14, SeekOrigin.Begin);
                                Y = packet3013.ReadSingle();
                            }
                            else
                            {
                                X = packet3013.ReadSingle();
                                packet3013.SeekRead(index + 10, SeekOrigin.Begin);
                                Y = packet3013.ReadSingle();
                            }
                            _charracter.XCoord = (int)Math.Floor((XX - 135) * 192 + X / 10);
                            _charracter.YCoord = (int)Math.Floor((YY - 92) * 192 + Y / 10);
                            _mainForm.UpdateCoord("X : " + _charracter.XCoord + "   " + "Y : " + _charracter.YCoord);
                        }

                        packet3013.Dispose();
                        _charracter.Opcode3013 = null;
                    }
                    break;
                case 0x3057:
                    {
                        uint tempID = packet.ReadUInt32();
                        packet.SeekRead(6, SeekOrigin.Begin);

                        if (tempID == _charracter.Id)
                        {
                            byte check = packet.ReadUInt8();
                            if (check == 1)
                            {
                                _charracter.CurrentHP = packet.ReadUInt32();
                            }
                            else if (check == 2)
                            {
                                _charracter.CurrentMP = packet.ReadUInt32();
                            }
                        }
                        _mainForm.UpdateProgressBarValue(_charracter.MaxHP, _charracter.CurrentHP, _charracter.MaxMP, _charracter.CurrentMP);
                    }
                    break;
                case 0x3013:
                    {
                        //Print(packet, "S->P");
                        _charracter.Opcode3013 = packet;
                        packet.SeekRead(42, SeekOrigin.Begin);
                        _charracter.CurrentHP = packet.ReadUInt32();
                        _charracter.CurrentMP = packet.ReadUInt32();
                        //_mainForm.UpdateProgressBarValue(_charracter.MaxHP, _charracter.CurrentHP, _charracter.MaxMP, _charracter.CurrentMP);
                    }
                    break;
                case 0xB021:
                    {
                        byte XX = 0, YY = 0;
                        ushort X = 0, Y = 0;
                        uint uintObjectID = packet.ReadUInt32();
                        byte byteDes = packet.ReadUInt8();
                        XX = packet.ReadUInt8();
                        YY = packet.ReadUInt8();
                        packet.SeekRead(5, SeekOrigin.Begin);
                        ushort zonetype = packet.ReadUInt16();
                        packet.SeekRead(7, SeekOrigin.Begin);
                        if (byteDes != 0)
                        {
                            if (uintObjectID == _charracter.Id)
                            {
                                if (zonetype >= 32769 && zonetype <= 32775)
                                {
                                    X = (ushort)(packet.ReadUInt16() - packet.ReadUInt16());
                                    packet.SeekRead(15, SeekOrigin.Begin);
                                    Y = (ushort)(packet.ReadUInt16() - packet.ReadUInt16());
                                }
                                else
                                {
                                    X = packet.ReadUInt16();
                                    packet.ReadUInt16();
                                    Y = packet.ReadUInt16();
                                }
                                _charracter.XCoord = (int)Math.Floor((XX - 135) * 192 + X / 10.0);
                                _charracter.YCoord = (int)Math.Floor((YY - 92) * 192 + Y / 10.0);

                                _mainForm.UpdateCoord("X : " + _charracter.XCoord + "   " + "Y : " + _charracter.YCoord);
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
            return retval;
        }
예제 #4
0
        protected virtual void Dispose(bool disposeManagedResources)
        {
            if (!this.disposed)
            {
                if (disposeManagedResources)
                {
                    // dispose managed resources
                    if (_localContext != null)
                    {
                        _localContext.Dispose();
                        _localContext = null;
                    }

                    if (_remoteContext != null)
                    {
                        _remoteContext.Dispose();
                        _remoteContext = null;
                    }

                    if (_outgoingPackets != null)
                    {
                        foreach (var kvp in _outgoingPackets)
                        {
                            kvp.Value.Dispose();
                        }
                        _outgoingPackets = null;
                    }

                    if (_incomingPackets != null)
                    {
                        foreach (var packet in _incomingPackets)
                        {
                            packet.Dispose();
                        }
                        _incomingPackets = null;
                    }
                }
                // dispose unmanaged resources
                disposed = true;
            }
        }