Ejemplo n.º 1
0
		public bool CreateCharacterIfNeeded(string name, ref CharacterRenderData[] loginData)
		{
			if (loginData == null || loginData.Length == 0)
			{
				CharacterReply charReply;
				var res = _api.CharacterRequest(out charReply);

				if (!res || charReply != CharacterReply.Ok)
				{
					_errorMessage("Character create request failed");
					return false;
				}

				var rand = new Random();

				res = _api.CharacterCreate((byte)rand.Next(1), (byte)rand.Next(0, 20), (byte)rand.Next(0, 9), (byte)rand.Next(0, 5),
					name, out charReply, out loginData);
				if (!res || charReply != CharacterReply.Ok || loginData == null || loginData.Length == 0)
				{
					_errorMessage("Character create failed");
					return false;
				}

				_outputFunc(string.Format("Created character {0}", name));

				Thread.Sleep(500);
			}
			return true;
		}
Ejemplo n.º 2
0
        //handler for LOGIN_REPLY received from server
        private void _handleLoginReply(Packet pkt)
        {
            m_login_reply = (LoginReply)pkt.GetShort();

            if (m_login_reply == LoginReply.Ok)
            {
                byte numCharacters = pkt.GetChar();
                pkt.GetByte();
                pkt.GetByte();

                m_character_data = new CharacterRenderData[numCharacters];

                for (int i = 0; i < numCharacters; ++i)
                {
                    CharacterRenderData nextData = new CharacterRenderData(pkt);
                    m_character_data[i] = nextData;
                    if (255 != pkt.GetByte())
                    {
                        return;                         //malformed packet - time out and signal error
                    }
                }
            }

            m_login_responseEvent.Set();
        }
Ejemplo n.º 3
0
		public bool LoginToAccount(string name, string password, out CharacterRenderData[] loginData)
		{
			LoginReply loginReply;
			var res = _api.LoginRequest(name, password, out loginReply, out loginData);
			if (!res)
			{
				_errorMessage();
				return false;
			}
			if (loginReply != LoginReply.Ok)
			{
				_errorMessage("Login reply was invalid");
				return false;
			}
			return true;
		}
Ejemplo n.º 4
0
		public bool LoginRequest(string user, string pass, out LoginReply reply, out CharacterRenderData[] data)
		{
			reply = LoginReply.THIS_IS_WRONG;
			data = null;
			if (!m_client.ConnectedAndInitialized || !Initialized)
				return false;

			Packet pkt = new Packet(PacketFamily.Login, PacketAction.Request);
			pkt.AddBreakString(user);
			pkt.AddBreakString(pass);

			if(!m_client.SendPacket(pkt) || !m_login_responseEvent.WaitOne(Constants.ResponseTimeout))
				return false;

			reply = m_login_reply;
			if (reply == LoginReply.Ok && m_character_data != null)
			{
				data = m_character_data;
			}

			return true;
		}
Ejemplo n.º 5
0
		//handler for LOGIN_REPLY received from server
		private void _handleLoginReply(Packet pkt)
		{
			m_login_reply = (LoginReply)pkt.GetShort();

			if (m_login_reply == LoginReply.Ok)
			{
				byte numCharacters = pkt.GetChar();
				pkt.GetByte();
				pkt.GetByte();

				m_character_data = new CharacterRenderData[numCharacters];

				for (int i = 0; i < numCharacters; ++i)
				{
					CharacterRenderData nextData = new CharacterRenderData(pkt);
					m_character_data[i] = nextData;
					if (255 != pkt.GetByte())
						return; //malformed packet - time out and signal error
				}
			}

			m_login_responseEvent.Set();
		}
Ejemplo n.º 6
0
 public void ProcessCharacterData(CharacterRenderData[] dataArray)
 {
     CharData = new CharRenderData[dataArray.Length];
     for (int i = 0; i < CharData.Length; ++i)
     {
         CharData[i] = new CharRenderData
         {
             name = dataArray[i].Name,
             id = dataArray[i].ID,
             level = dataArray[i].Level,
             gender = dataArray[i].Gender,
             hairstyle = dataArray[i].HairStyle,
             haircolor = dataArray[i].HairColor,
             race = dataArray[i].Race,
             admin = (byte)dataArray[i].AdminLevel,
             boots = dataArray[i].Boots,
             armor = dataArray[i].Armor,
             hat = dataArray[i].Hat,
             shield = dataArray[i].Shield,
             weapon = dataArray[i].Weapon
         };
     }
 }
Ejemplo n.º 7
0
        public bool CharacterRemove(int id, out CharacterRenderData[] data)
        {
            data = null;
            if (!m_client.ConnectedAndInitialized || !Initialized)
                return false;

            Packet builder = new Packet(PacketFamily.Character, PacketAction.Remove);
            builder.AddShort(255);
            builder.AddInt(id);

            if (!m_client.SendPacket(builder) || !m_character_responseEvent.WaitOne(Constants.ResponseTimeout))
                return false;

            if (m_character_reply != CharacterReply.Deleted || m_character_data == null)
                return false;

            data = m_character_data;

            return true;
        }
Ejemplo n.º 8
0
        public bool CharacterCreate(byte gender, byte hairStyle, byte hairColor, byte race, string name, out CharacterReply reply, out CharacterRenderData[] data)
        {
            data = null;
            reply = CharacterReply.THIS_IS_WRONG;
            if (!m_client.ConnectedAndInitialized || !Initialized)
                return false;

            Packet builder = new Packet(PacketFamily.Character, PacketAction.Create);
            builder.AddShort(255);
            builder.AddShort(gender);
            builder.AddShort(hairStyle);
            builder.AddShort(hairColor);
            builder.AddShort(race);
            builder.AddByte(255);
            builder.AddBreakString(name);

            if (!m_client.SendPacket(builder) || !m_character_responseEvent.WaitOne(Constants.ResponseTimeout))
                return false;

            reply = m_character_reply;

            if (reply == CharacterReply.THIS_IS_WRONG || m_character_data == null || m_character_data.Length == 0)
                return false;

            data = m_character_data;

            return true;
        }
Ejemplo n.º 9
0
		public bool DoWelcomePacketsForFirstCharacter(CharacterRenderData[] loginData, out WelcomeRequestData welcomeReqData, out WelcomeMessageData welcomeMsgData)
		{
			welcomeMsgData = null;

			var res = _api.SelectCharacter(loginData[0].ID, out welcomeReqData);
			if (!res)
			{
				_errorMessage();
				return false;
			}

			Thread.Sleep(500);

			res = _api.WelcomeMessage(welcomeReqData.ActiveCharacterID, out welcomeMsgData);
			if (!res)
			{
				_errorMessage();
				return false;
			}
			return true;
		}