示例#1
0
        private bool Initialize(byte[] versionNumber, string hdSerialNum, out InitData data)
        {
            Initialized = false;
            data        = new InitData();
            if (!m_client.ConnectedAndInitialized || versionNumber.Length != 3 || hdSerialNum.Length == 0)
            {
                return(false);
            }

            Packet builder = new Packet(PacketFamily.Init, PacketAction.Init);

            builder.AddThree(Hashes.stupid_hash(new Random().Next(6, 12)));

            builder.AddChar(versionNumber[0]);
            builder.AddChar(versionNumber[1]);
            builder.AddChar(versionNumber[2]); //client version
            builder.AddChar(112);              //unknown
            builder.AddChar((byte)hdSerialNum.Length);
            builder.AddString(hdSerialNum);

            if (!m_client.SendRaw(builder))
            {
                return(false);
            }

            if (!m_init_responseEvent.WaitOne(Constants.ResponseTimeout))
            {
                return(false);
            }

            data = m_init_initData;

            return(true);
        }
示例#2
0
        private void _createInitMembers()
        {
            m_init_responseEvent = new AutoResetEvent(false);

            m_init_initData         = new InitData();
            m_init_requestedMap     = 0;
            m_init_onlinePlayerList = null;

            m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.Init, PacketAction.Init), _handleInitInit, false);
        }
示例#3
0
        private void _handleInitInit(Packet pkt)
        {
            InitReply response = (InitReply)pkt.GetByte();

            switch (response)
            {
            case InitReply.INIT_FRIEND_LIST_PLAYERS:
            case InitReply.INIT_PLAYERS:
                if (!m_client.ExpectingPlayerList)
                {
                    break;
                }
                _handlePlayerList(pkt, response == InitReply.INIT_FRIEND_LIST_PLAYERS);
                break;

            case InitReply.INIT_BANNED:
            {
                //sends INIT_BANNED in response to WARP_TAKE packet
                if (m_client.ExpectingFile)
                {
                    response = InitReply.INIT_FILE_MAP;
                    goto case InitReply.INIT_FILE_MAP;
                }

                InitBanType BanType     = (InitBanType)pkt.GetByte();
                byte        BanMinsLeft = 0;
                if (BanType == InitBanType.INIT_BAN_TEMP)
                {
                    BanMinsLeft = pkt.GetByte();
                }

                m_init_initData = new InitData {
                    ServerResponse = response, BanType = BanType, BanMinsLeft = BanMinsLeft
                };
            }
            break;

            case InitReply.INIT_OUT_OF_DATE:
            {
                pkt.GetChar();                         //always 0
                pkt.GetChar();                         //always 0
                m_init_initData = new InitData
                {
                    ServerResponse        = response,
                    RequiredVersionNumber = pkt.GetChar()                             //actual version number required
                };
            }
            break;

            case InitReply.INIT_OK:
            {
                m_init_initData = new InitData
                {
                    ServerResponse = response,
                    seq_1          = pkt.GetByte(),
                    seq_2          = pkt.GetByte(),
                    //These are switched around from the server:
                    //	the server's encode function is the client's decode function (and vice versa)
                    emulti_d = pkt.GetByte(),
                    emulti_e = pkt.GetByte(),
                    clientID = pkt.GetShort(),
                    response = pkt.GetThree()
                };
            }
            break;

            //file transfer is all handled the same way
            case InitReply.INIT_FILE_EIF:
            case InitReply.INIT_FILE_ENF:
            case InitReply.INIT_FILE_ESF:
            case InitReply.INIT_FILE_ECF:
            case InitReply.INIT_FILE_MAP:
            case InitReply.INIT_MAP_MUTATION:
            {
                string localDir = response == InitReply.INIT_FILE_MAP || response == InitReply.INIT_MAP_MUTATION ? "maps" : "pub";

                if (response == InitReply.INIT_MAP_MUTATION)
                {
                    m_init_requestedMap = 0;
                }

                if (!Directory.Exists(localDir))
                {
                    Directory.CreateDirectory(localDir);
                }

                string filename;
                if (response == InitReply.INIT_FILE_EIF)
                {
                    filename = "dat001.eif";
                }
                else if (response == InitReply.INIT_FILE_ENF)
                {
                    filename = "dtn001.enf";
                }
                else if (response == InitReply.INIT_FILE_ESF)
                {
                    filename = "dsl001.esf";
                }
                else if (response == InitReply.INIT_FILE_ECF)
                {
                    filename = "dat001.ecf";
                }
                else
                {
                    filename = string.Format("{0,5:D5}.emf", m_init_requestedMap);
                }

                using (FileStream fs = File.Create(Path.Combine(localDir, filename)))
                {
                    int dataLen = pkt.Length - 3;
                    if (dataLen == 0)
                    {
                        throw new FileLoadException();
                    }
                    fs.Write(pkt.GetBytes(dataLen), 0, dataLen);
                }

                if (response == InitReply.INIT_MAP_MUTATION && OnMapMutation != null)
                {
                    OnMapMutation();
                }
            }
            break;
            }

            m_client.ExpectingFile       = false;
            m_client.ExpectingPlayerList = false;
            m_init_responseEvent.Set();             //packet was handled
        }
示例#4
0
 public bool Initialize(byte versionMajor, byte versionMinor, byte versionBuild, string hdSerialNum, out InitData data)
 {
     return(Initialize(new[] { versionMajor, versionMinor, versionBuild }, hdSerialNum, out data));
 }
示例#5
0
 public void SetInitData(InitData data)
 {
     m_packetProcessor.SetMulti(data.emulti_d, data.emulti_e);
     UpdateSequence(data.seq_1 * 7 - 11 + data.seq_2 - 2);
 }
示例#6
0
        private void _handleInitInit(Packet pkt)
        {
            InitReply response = (InitReply)pkt.GetByte();
            switch (response)
            {
                case InitReply.INIT_FRIEND_LIST_PLAYERS:
                case InitReply.INIT_PLAYERS:
                    if (!m_client.ExpectingPlayerList)
                        break;
                    _handlePlayerList(pkt, response == InitReply.INIT_FRIEND_LIST_PLAYERS);
                    break;
                case InitReply.INIT_BANNED:
                {
                    //sends INIT_BANNED in response to WARP_TAKE packet
                    if (m_client.ExpectingFile)
                    {
                        response = InitReply.INIT_FILE_MAP;
                        goto case InitReply.INIT_FILE_MAP;
                    }

                    InitBanType BanType = (InitBanType) pkt.GetByte();
                    byte BanMinsLeft = 0;
                    if (BanType == InitBanType.INIT_BAN_TEMP)
                        BanMinsLeft = pkt.GetByte();

                    m_init_initData = new InitData {ServerResponse = response, BanType = BanType, BanMinsLeft = BanMinsLeft};
                }
                    break;
                case InitReply.INIT_OUT_OF_DATE:
                {
                    pkt.GetChar(); //always 0
                    pkt.GetChar(); //always 0
                    m_init_initData = new InitData
                    {
                        ServerResponse = response,
                        RequiredVersionNumber = pkt.GetChar() //actual version number required
                    };
                }
                    break;
                case InitReply.INIT_OK:
                {
                    m_init_initData = new InitData
                    {
                        ServerResponse = response,
                        seq_1 = pkt.GetByte(),
                        seq_2 = pkt.GetByte(),
                        //These are switched around from the server:
                        //	the server's encode function is the client's decode function (and vice versa)
                        emulti_d = pkt.GetByte(),
                        emulti_e = pkt.GetByte(),
                        clientID = pkt.GetShort(),
                        response = pkt.GetThree()
                    };
                }
                    break;
                    //file transfer is all handled the same way
                case InitReply.INIT_FILE_EIF:
                case InitReply.INIT_FILE_ENF:
                case InitReply.INIT_FILE_ESF:
                case InitReply.INIT_FILE_ECF:
                case InitReply.INIT_FILE_MAP:
                case InitReply.INIT_MAP_MUTATION:
                {
                    string localDir = response == InitReply.INIT_FILE_MAP || response == InitReply.INIT_MAP_MUTATION ? "maps" : "pub";

                    if (response == InitReply.INIT_MAP_MUTATION)
                        m_init_requestedMap = 0;

                    if (!Directory.Exists(localDir))
                        Directory.CreateDirectory(localDir);

                    string filename;
                    if (response == InitReply.INIT_FILE_EIF)
                        filename = "dat001.eif";
                    else if (response == InitReply.INIT_FILE_ENF)
                        filename = "dtn001.enf";
                    else if (response == InitReply.INIT_FILE_ESF)
                        filename = "dsl001.esf";
                    else if (response == InitReply.INIT_FILE_ECF)
                        filename = "dat001.ecf";
                    else
                        filename = string.Format("{0,5:D5}.emf", m_init_requestedMap);

                    using (FileStream fs = File.Create(Path.Combine(localDir, filename)))
                    {
                        int dataLen = pkt.Length - 3;
                        if (dataLen == 0)
                            throw new FileLoadException();
                        fs.Write(pkt.GetBytes(dataLen), 0, dataLen);
                    }

                    if (response == InitReply.INIT_MAP_MUTATION && OnMapMutation != null)
                    {
                        OnMapMutation();
                    }
                }
                    break;
            }

            m_client.ExpectingFile = false;
            m_client.ExpectingPlayerList = false;
            m_init_responseEvent.Set(); //packet was handled
        }
示例#7
0
        private void _createInitMembers()
        {
            m_init_responseEvent = new AutoResetEvent(false);

            m_init_initData = new InitData();
            m_init_requestedMap = 0;
            m_init_onlinePlayerList = null;

            m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.Init, PacketAction.Init), _handleInitInit, false);
        }
示例#8
0
        private bool Initialize(byte[] versionNumber, string hdSerialNum, out InitData data)
        {
            Initialized = false;
            data = new InitData();
            if (!m_client.ConnectedAndInitialized || versionNumber.Length != 3 || hdSerialNum.Length == 0)
            {
                return false;
            }

            Packet builder = new Packet(PacketFamily.Init, PacketAction.Init);

            builder.AddThree(Hashes.stupid_hash(new Random().Next(6, 12)));

            builder.AddChar(versionNumber[0]);
            builder.AddChar(versionNumber[1]);
            builder.AddChar(versionNumber[2]); //client version
            builder.AddChar(112); //unknown
            builder.AddChar((byte)hdSerialNum.Length);
            builder.AddString(hdSerialNum);

            if (!m_client.SendRaw(builder))
                return false;

            if (!m_init_responseEvent.WaitOne(Constants.ResponseTimeout))
                return false;

            data = m_init_initData;

            return true;
        }
示例#9
0
 public bool Initialize(byte versionMajor, byte versionMinor, byte versionBuild, string hdSerialNum, out InitData data)
 {
     return Initialize(new[] {versionMajor, versionMinor, versionBuild}, hdSerialNum, out data);
 }
示例#10
-1
 public void SetInitData(InitData data)
 {
     m_packetProcessor.SetMulti(data.emulti_d, data.emulti_e);
     UpdateSequence(data.seq_1*7 - 11 + data.seq_2 - 2);
 }