Results 1 to 11 of 11
  1. #1
    BRDominik's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Posts
    161
    Reputation
    10
    Thanks
    76
    My Mood
    Blah

    K-Relay UseItem Packet not sending from time to time

    Hey Guys,

    I don't know if any of you experienced this problem, but I'm making a auto hp/mp pot plugin for K-Relay and for some reason, the UseItem Packet is not sending to server or processed by it correctly. Sometimes it does use the hp potion, but others it simply doesn't do anything.

    This is what I'm doing to use an hp potion:
    Code:
    UseItemPacket useItem = (UseItemPacket)Packet.Create(PacketType.USEITEM);
    useItem.Time = client.Time;
    useItem.SlotObject = (SlotObject)new SlotObject();
    useItem.SlotObject.ObjectId = (int)client.PlayerData.OwnerObjectId;
    useItem.SlotObject.SlotId = (byte)254;
    useItem.SlotObject.ObjectType = (short)2594;
    useItem.ItemUsePos = client.PlayerData.Pos;
    useItem.UseType = 0;
    client.SendToServer(useItem);
    Any ideas?

    Cheers,
    BRDominik

  2. #2
    BRDominik's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Posts
    161
    Reputation
    10
    Thanks
    76
    My Mood
    Blah
    bump

    And yes. I've tried to change the Time attribute by increasing and decreasing it, but it still only works randomly.

  3. #3
    DonJuan13's Avatar
    Join Date
    May 2014
    Gender
    male
    Posts
    62
    Reputation
    10
    Thanks
    76
    I had the same problem with sending INVSWAP packets so I wrote a sort of checker. I made a variable _old that stores the amount of hp pots before sending the packet (client.PlayerData.HealthpotCount). In my OnUpdate method, I have it check if the current amount of hp pots is less than the old amount (currHP >= _old). If not it needs to try again. I would be happy to share my source code w/ you and would appreciate credit if you use my method :)

    *note: if it fails too many times (15-20+?) it will cause the client to disconnect but that hasn't happened yet for me

  4. #4
    krazyshank's Avatar
    Join Date
    Jan 2012
    Gender
    male
    Location
    RealmStock
    Posts
    2,589
    Reputation
    467
    Thanks
    16,666
    My Mood
    Angelic
    I've had this problem too while implementing auto ability, and have not yet solved it.
    I'm not sure what the server isn't liking about our requests, but it outright ignores them unpredictably.

  5. #5
    BRDominik's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Posts
    161
    Reputation
    10
    Thanks
    76
    My Mood
    Blah
    Quote Originally Posted by DonJuan13 View Post
    I had the same problem with sending INVSWAP packets so I wrote a sort of checker. I made a variable _old that stores the amount of hp pots before sending the packet (client.PlayerData.HealthpotCount). In my OnUpdate method, I have it check if the current amount of hp pots is less than the old amount (currHP >= _old). If not it needs to try again. I would be happy to share my source code w/ you and would appreciate credit if you use my method

    *note: if it fails too many times (15-20+?) it will cause the client to disconnect but that hasn't happened yet for me
    Interesting approach. I thought of that one if I didn't find a better way, which I'm still looking for. Also I would love to see your source code, always excited to see other people's code and do not worry I always credit people, even when I'm using it privately.

    Quote Originally Posted by krazyshank View Post
    I've had this problem too while implementing auto ability, and have not yet solved it.
    I'm not sure what the server isn't liking about our requests, but it outright ignores them unpredictably.
    Could it be a due to a mistake in the implementation of those packets? I'm almost starting to look at the source code to see if there is something wrong in it. I might even start comparing with Realm Relay since, as I recall, does not have this problem.
    Last edited by BRDominik; 12-08-2015 at 03:01 PM.

  6. #6
    krazyshank's Avatar
    Join Date
    Jan 2012
    Gender
    male
    Location
    RealmStock
    Posts
    2,589
    Reputation
    467
    Thanks
    16,666
    My Mood
    Angelic
    Quote Originally Posted by BRDominik View Post
    Interesting approach. I thought of that one if I didn't find a better way, which I'm still looking for. Also I would love to see your source code, always excited to see other people's code and do not worry I always credit people, even when I'm using it privately.


    Could it be a due to a mistake in the implementation of those packets? I'm almost starting to look at the source code to see if there is something wrong in it. I might even start comparing with Realm Relay since, as I recall, does not have this problem.
    After some testing I think it's the Time that's the issue.
    In K Relay, Client.Time represents the last time that the client communicated to the server, not an actual calculation of the client's time.

    You can pretty easily calculate the client's current time by doing something like this:
    Store the last time the client sent to the server, for example by saving the time sent in MOVE packets.
    Then implement a method like this one:
    Code:
    public int GetTime(ClientInfo client)
    {
         return client.Time + (Environment.TickCount - _lastSentTime);
    }
    You'll probably want to make this compatible with multiple clients, so to do that you'd do something like this:
    Code:
    private Dictionary<ClientInfo, int> _clientTimes = new Dictionary<ClientInfo, int>();
    
    public void Initialize(Proxy proxy)
    {
         proxy.HookPacket<MovePacket>(OnMove);
    }
    
    private void OnMove(ClientInfo client, MovePacket move)
    {
         if (!_clientTimes.ContainsKey(client))
              _clientTimes.Add(client, move.Time);
    
         _clientTimes[client] = move.Time;
    }
    
    public int GetTime(ClientInfo client)
    {
         return client.Time + (Environment.TickCount - _clientTimes[client]);
    }

  7. The Following User Says Thank You to krazyshank For This Useful Post:

    BRDominik (12-08-2015)

  8. #7
    BRDominik's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Posts
    161
    Reputation
    10
    Thanks
    76
    My Mood
    Blah
    Quote Originally Posted by krazyshank View Post
    After some testing I think it's the Time that's the issue.
    In K Relay, Client.Time represents the last time that the client communicated to the server, not an actual calculation of the client's time.

    You can pretty easily calculate the client's current time by doing something like this:
    Store the last time the client sent to the server, for example by saving the time sent in MOVE packets.
    Then implement a method like this one:
    Code:
    public int GetTime(ClientInfo client)
    {
         return client.Time + (Environment.TickCount - _lastSentTime);
    }
    You'll probably want to make this compatible with multiple clients, so to do that you'd do something like this:
    Code:
    private Dictionary<ClientInfo, int> _clientTimes = new Dictionary<ClientInfo, int>();
    
    public void Initialize(Proxy proxy)
    {
         proxy.HookPacket<MovePacket>(OnMove);
    }
    
    private void OnMove(ClientInfo client, MovePacket move)
    {
         if (!_clientTimes.ContainsKey(client))
              _clientTimes.Add(client, move.Time);
    
         _clientTimes[client] = move.Time;
    }
    
    public int GetTime(ClientInfo client)
    {
         return client.Time + (Environment.TickCount - _clientTimes[client]);
    }
    Interesting, this does indeed work, but I get dc. I found out that is due to the returned time of GetTime, being way off the correct time, like millions of ticks(s) ahead. The correct implementation is to get the enviromental time instead of client time in OnMove function.

    Code:
    private void OnMove(Client client, Packet packet)
    {
        if (!_clientTimes.ContainsKey(client))
            _clientTimes.Add(client, Environment.TickCount);
    
        _clientTimes[client] = Environment.TickCount;
    }
    From what I could test, the server is now accepting all kind of use packets without any problem.
    Last edited by BRDominik; 12-08-2015 at 03:57 PM. Reason: I'm dumb

  9. #8
    krazyshank's Avatar
    Join Date
    Jan 2012
    Gender
    male
    Location
    RealmStock
    Posts
    2,589
    Reputation
    467
    Thanks
    16,666
    My Mood
    Angelic
    Quote Originally Posted by BRDominik View Post
    Interesting, this does indeed work, but I get dc. I found out that is due to the returned time of GetTime, being way off the correct time, like millions of ticks(s) ahead. The correct implementation is to get the enviromental time instead of client time in OnMove function.

    Code:
    private void OnMove(Client client, Packet packet)
    {
        if (!_clientTimes.ContainsKey(client))
            _clientTimes.Add(client, Environment.TickCount);
    
        _clientTimes[client] = Environment.TickCount;
    }
    From what I could test, the server is now accepting all kind of use packets without any problem.
    Oops I made a small mistake in that code.

    Instead of
    Code:
    private void OnMove(ClientInfo client, MovePacket move)
    {
         if (!_clientTimes.ContainsKey(client))
              _clientTimes.Add(client, move.Time);
    
         _clientTimes[client] = move.Time;
    }
    It should be
    Code:
    private void OnMove(ClientInfo client, MovePacket move)
    {
         if (!_clientTimes.ContainsKey(client))
              _clientTimes.Add(client, Environment.TickCount);
    
         _clientTimes[client] = Environment.TickCount;
    }
    - - - Updated - - -

    Quote Originally Posted by krazyshank View Post
    Oops I made a small mistake in that code.

    Instead of
    Code:
    private void OnMove(ClientInfo client, MovePacket move)
    {
         if (!_clientTimes.ContainsKey(client))
              _clientTimes.Add(client, move.Time);
    
         _clientTimes[client] = move.Time;
    }
    It should be
    Code:
    private void OnMove(ClientInfo client, MovePacket move)
    {
         if (!_clientTimes.ContainsKey(client))
              _clientTimes.Add(client, Environment.TickCount);
    
         _clientTimes[client] = Environment.TickCount;
    }
    Lol didn't read your response fully I guess! Yep, you got it.

  10. #9
    BRDominik's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Posts
    161
    Reputation
    10
    Thanks
    76
    My Mood
    Blah
    It's fine. You can close this thread if you want. Also, thank you for creating this awesome program. I'm enjoying a lot learning C#.

  11. #10
    DonJuan13's Avatar
    Join Date
    May 2014
    Gender
    male
    Posts
    62
    Reputation
    10
    Thanks
    76
    BRDominik would you be kind enough to share you implementation of this time method. I am rather new to developing these plugins and would appreciate the help

  12. #11
    BRDominik's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Posts
    161
    Reputation
    10
    Thanks
    76
    My Mood
    Blah
    Quote Originally Posted by DonJuan13 View Post
    BRDominik would you be kind enough to share you implementation of this time method. I am rather new to developing these plugins and would appreciate the help
    All the implementation you need is in the code krazyshank just posted here. Just include them in your code and you GetTime(client) instead of client.Time. If you still can't do it msg me.

Similar Threads

  1. DO NOT BUY FROM Warpath37 OR SniperBoy34
    By schiz in forum Selling Accounts/Keys/Items
    Replies: 20
    Last Post: 07-12-2010, 08:22 PM
  2. New hack???(not CFPUB from dave)
    By mcduvida97 in forum CrossFire Help
    Replies: 6
    Last Post: 05-04-2010, 07:20 PM
  3. WDF....i got disconnect from sever 13 times today
    By elias1899 in forum CrossFire Discussions
    Replies: 2
    Last Post: 04-29-2010, 06:52 AM
  4. Super Mods/Cross moding did not come from MPGH
    By jesuscriest in forum Combat Arms Mod Discussion
    Replies: 42
    Last Post: 02-22-2010, 04:09 PM
  5. DO NOT BUY FROM
    By killemslow in forum Flaming & Rage
    Replies: 13
    Last Post: 07-28-2009, 01:58 PM