bump
And yes. I've tried to change the Time attribute by increasing and decreasing it, but it still only works randomly.
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:
Any ideas?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);
Cheers,
BRDominik
bump
And yes. I've tried to change the Time attribute by increasing and decreasing it, but it still only works randomly.
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
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.
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.
Last edited by BRDominik; 12-08-2015 at 03:01 PM.
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:
You'll probably want to make this compatible with multiple clients, so to do that you'd do something like this:Code:public int GetTime(ClientInfo client) { return client.Time + (Environment.TickCount - _lastSentTime); }
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]); }
BRDominik (12-08-2015)
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.
From what I could test, the server is now accepting all kind of use packets without any problem.Code:private void OnMove(Client client, Packet packet) { if (!_clientTimes.ContainsKey(client)) _clientTimes.Add(client, Environment.TickCount); _clientTimes[client] = Environment.TickCount; }
Last edited by BRDominik; 12-08-2015 at 03:57 PM. Reason: I'm dumb
Oops I made a small mistake in that code.
Instead of
It should beCode:private void OnMove(ClientInfo client, MovePacket move) { if (!_clientTimes.ContainsKey(client)) _clientTimes.Add(client, move.Time); _clientTimes[client] = move.Time; }
- - - Updated - - -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.
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#.
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