SolvedProblem with K-Relay

Posts 115 of 17 · Page 1 of 2
Problem with K-Relay
Upon the most recent update of the game I haven't been able to use K-Relay. I've tried both of the most recent releases to no avail. Upon attempting to connect to Proxy through game, this happens:

[GameData] Mapped 333 tiles.
[GameData] Mapped 94 packets.
[GameData] Mapped 1294 items.
[GameData] Mapped 3854 objects.
[GameData] Mapped 22 servers.
[GameData] Successfully loaded game data.
[K Relay] Initialization complete.
[Listener] Starting local listener...
[Listener] Local listener started.
[Listener] Client received.
[Error] An exception was thrown
within RemoteRead (isClient = True)
at PacketBuffer.Resize

New buffer size is too large
[Client] Disconnected.

So I downloaded the other release of KRelay and had the same issue. I even went to K-Relays github and downloaded the project and updated packets.xml and built the application. I also tried to remove all the plugins from both and try to run it that way, once again, no luck. I really don't know what is going on here and any help would be appreciated.

- - - Updated - - -

And if it's any help:

I tired to reply to this earlier but the site was down for some reason.

Since you have the source and can compile it for yourself, instead of me uploading a version to get debug output can you just add some and recompile it and run it for us? Im interested to see the actual size that is being passed to the function that is throwing the error. If you can, could you edit the lib_k_relay project, the file "Networking/Packets/PacketBuffer.cs". On line 22, if you change it to something like:
Code:
throw new ArgumentException("New buffer size is too large: " + newSize);
Then when you run it, if it throws that error again it should tell you the size its trying to allocate. That might help to understand why its doing this for some people.
In the source there is no PacketBuffer.cs, could this be causing the issue?



- - - Updated - - -

Disregard, I found it.



- - - Updated - - -

So I edited the code and this is the error K-Relay throws back when attempting to connect. I'm too new to this to think anything of it @toddddd


[K Relay] Initialization complete.
[Listener] Starting local listener...
[Listener] Local listener started.
[Listener] Client received.
[Error] An exception was thrown
within RemoteRead (isClient = True)
at PacketBuffer.Resize

System.ArgumentException: New buffer size is too large: 1014001516
at Lib_K_Relay.Networking.PacketBuffer.Resize(Int32 newSize) in C:\Users\lance\Desktop\K_Relay-master\Lib K Relay\Networking\PacketBuffer.cs:line 22
at Lib_K_Relay.Networking.Client.<>c__DisplayClass40_ 0.<RemoteRead>b__0() in C:\Users\lance\Desktop\K_Relay-master\Lib K Relay\Networking\Client.cs:line 213
at Lib_K_Relay.Utilities.PluginUtils.ProtectedInvoke( Action action, String errorProvider, Type filteredException) in C:\Users\lance\Desktop\K_Relay-master\Lib K Relay\Utilities\PluginUtils.cs:line 38
[Client] Disconnected.
Quote Originally Posted by Alt_World View Post
1014001516
http://www.mpgh.net/forum/showthread...2596&p=8659883
Seems like this problem occurred before KRelay existed.

Try replacing
Code:
            if (newSize > 1048576)
                throw new ArgumentException("New buffer size is too large");

            byte[] old = Bytes;
            Bytes = new byte[newSize];
            Bytes[0] = old[0];
            Bytes[1] = old[1];
            Bytes[2] = old[2];
            Bytes[3] = old[3];
with
Code:
 try{ byte[] old = Bytes;
            Bytes = new byte[newSize];
            Bytes[0] = old[0];
            Bytes[1] = old[1];
            Bytes[2] = old[2];
            Bytes[3] = old[3];
}catch (Exception ex) { Console.Writeline(ex.ToString()); }
This doesn't check for new size. To be honest, if it exists, it should have a reason, but try never the less.

You will most likely get an exception from it. Paste it here.
So I tried changing the buffer size previously and it didn't work, infact it was almost a repeat of what just happened.
When loading the client into proxy KRelay doesnt throw back an error at all.

[Interface] Loaded and attached OryxShop Blocker.
[Interface] Loaded and attached Teleport Tools.
[Interface] Loaded and attached Vault Highlight.
[Interface] Loaded and attached Live World Editor.
[K Relay] Initialization complete.
[Listener] Starting local listener...
[Listener] Local listener started.
[Listener] Client received.
[Client] Disconnected.
[Listener] Stopping local listener...
[Error] An exception was thrown
within LocalConnect
at <>c__DisplayClass31_0.<LocalConnect>b__0

System.*********enceException: Object reference not set to an instance of an object.
at Lib_K_Relay.Proxy.<>c__DisplayClass31_0.<LocalConn ect>b__0() in C:\Users\lance\Desktop\K_Relay-master\Lib K Relay\Proxy.cs:line 121
at Lib_K_Relay.Utilities.PluginUtils.ProtectedInvoke( Action action, String errorProvider, Type filteredException) in C:\Users\lance\Desktop\K_Relay-master\Lib K Relay\Utilities\PluginUtils.cs:line 38

But this time there was an error after stopping proxy on KRelay. @New
So you dont have an error when connecting anymore? Are you able to play just fine or does the error prevent game play? I have noticed that i will occasionally get an error when playing (and my version is compiled straight from the source with updated resources) but it doesnt prevent me from playing at all. The suggestion that PKTINOS gave was exactly what i was going to suggest as well, im not sure of the reason for the size limitation but it is clearly what is preventing you from playing. Hopefully someone with better knowledge of k-relay can jump in an give a better answer though.
Yea it prevents gameplay. Still unfixed.
Ah gotcha, though you said the program only crashed when you stopped the proxy, meaning it runs fine until then.

Anyways ive been looking at the thread that PKTINOS posted as well as searching the forums for more answers. I really cant give you a reason why, but sounds like what they are saying is that flash is sending a "<policy-file-request/>" and the proxy has to reply with the correct cross-domain-policy xml. Im not sure why this isnt something built into k-relay already. I also dont really understand why it is doing this for some people but not everyone.

Have you tried to connect to a normal server first, and then try to connect to the proxy server? Wondering if that might work or not.


Looking at the post PKTINOS linked, nilly talks about using source from this post (i think): http://www.mpgh.net/forum/599-realm-...roxy-base.html
I took a look at the source of that proxy and it contain this, which is the kind of reply the client is looking for from the proxy:
Code:
public static final String POLICY_XML = "<?xml version=\"1.0\"?>" + "<cross-domain-policy>" + "<allow-access-from domain=\"*\" to-ports=\"*\" />" + "</cross-domain-policy>\n\u0000";
But i couldnt find any reference to "policy-file-request" or "cross-domain-policy" anywhere in k-relay's source. It sounds like it will need to be edited to check if the packet is "<policy-file-request/>", and if so reply with the correct cross-domain-policy xml. Or there has to be some workaround to avoid needing to send this, since not everyone is having this issue. Ill see if i can find anything else related to this though and let you know.



-- edit --

Ive done a little more reading. So its was mentioned in the post PKTINOS linked, there needs to be a separate connection listener on port 843. Basically this listener needs to check if the data sent to it is "<policy-file-request/>" (easiest to just check if the data contains the word policy), then respond with the correct cross-domain-policy xml. For example:
Code:
<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\"/></cross-domain-policy>\0
This is the answer to the problem, now someone needs to get k-relay programmed to do this. Im not very C# savvy but ill take a look and see if i can get something like that set up. If anyone else wants to do this it would be great as it is the answer to the problem people have been posting.


-- edit --

Heres my attempt at coding what i was talking about above. First, open "Proxy.cs" in lib_k_relay. Next, create a new TcpListener below "_localListener". I named it "_policyListener". Then, in the Start() function, below the _localListener code add:
Code:
_policyListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 843);
_policyListener.Start();
_policyListener.BeginAcceptTcpClient(PolicyConnect, null);
That should create the listener on the port that is supposedly the one that is used to send/receive the policy info. Now, go below the function LocalConnect() and make a new function called PolicyConnect(). I started by copying the LocalConnect() function and modifying it as needed. Here is what i came up with:
Code:
private void PolicyConnect(IAsyncResult ar)
{
	PluginUtils.ProtectedInvoke(() =>
	{
		TcpClient policyClient = _policyListener.EndAcceptTcpClient(ar);

		PluginUtils.Log("PolicyListener", "PolicyClient connected.");

		NetworkStream stream = policyClient.GetStream();
		StreamReader read = new StreamReader(stream, Encoding.UTF8);
		StreamWriter write = new StreamWriter(stream, Encoding.UTF8);


		string msg = "";
		char[] data = new char[256];
		int bytes = read.ReadBlock(data, 0, data.Length);
		msg = new string(data);

		PluginUtils.Log("PolicyListener", "Received: " + msg);
		if (msg.Contains("policy"))
		{
			write.Write("<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>\0");
			write.Flush();
		}

		read.Close();
		write.Close();
		stream.Close();
		policyClient.Close();

				
	}, "PolicyConnect", typeof(ObjectDisposedException));

	PluginUtils.ProtectedInvoke(() =>
	{
		if (_policyListener != null) _policyListener.BeginAcceptTcpClient(PolicyConnect, null);
	}, "PolicyListenerBeginListen");
}
Then try to compile and run it. I made these changes and ran it and it didnt cause the program to not work, so thats good. I cant say if this will work for you or not since i never had the issue you are having. But this should be close to the right solution. Hopefully if this doesnt work then someone with better C# knowledge can jump in and fix it so it does work for you. If this does work for you then let me know so i can get my code updated and posted so everyone else with this problem can use it.

Hope this works, or at least is on the right track.
Quote Originally Posted by toddddd View Post
Ah gotcha, though you said the program only crashed when you stopped the proxy, meaning it runs fine until then.

Anyways ive been looking at the thread that PKTINOS posted as well as searching the forums for more answers. I really cant give you a reason why, but sounds like what they are saying is that flash is sending a "<policy-file-request/>" and the proxy has to reply with the correct cross-domain-policy xml. Im not sure why this isnt something built into k-relay already. I also dont really understand why it is doing this for some people but not everyone.

Have you tried to connect to a normal server first, and then try to connect to the proxy server? Wondering if that might work or not.


Looking at the post PKTINOS linked, nilly talks about using source from this post (i think): http://www.mpgh.net/forum/599-realm-...roxy-base.html
I took a look at the source of that proxy and it contain this, which is the kind of reply the client is looking for from the proxy:
Code:
public static final String POLICY_XML = "<?xml version=\"1.0\"?>" + "<cross-domain-policy>" + "<allow-access-from domain=\"*\" to-ports=\"*\" />" + "</cross-domain-policy>\n\u0000";
But i couldnt find any reference to "policy-file-request" or "cross-domain-policy" anywhere in k-relay's source. It sounds like it will need to be edited to check if the packet is "<policy-file-request/>", and if so reply with the correct cross-domain-policy xml. Or there has to be some workaround to avoid needing to send this, since not everyone is having this issue. Ill see if i can find anything else related to this though and let you know.



-- edit --

Ive done a little more reading. So its was mentioned in the post PKTINOS linked, there needs to be a separate connection listener on port 843. Basically this listener needs to check if the data sent to it is "<policy-file-request/>" (easiest to just check if the data contains the word policy), then respond with the correct cross-domain-policy xml. For example:
Code:
<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\"/></cross-domain-policy>\0
This is the answer to the problem, now someone needs to get k-relay programmed to do this. Im not very C# savvy but ill take a look and see if i can get something like that set up. If anyone else wants to do this it would be great as it is the answer to the problem people have been posting.


-- edit --

Heres my attempt at coding what i was talking about above. First, open "Proxy.cs" in lib_k_relay. Next, create a new TcpListener below "_localListener". I named it "_policyListener". Then, in the Start() function, below the _localListener code add:
Code:
_policyListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 843);
_policyListener.Start();
_policyListener.BeginAcceptTcpClient(PolicyConnect, null);
That should create the listener on the port that is supposedly the one that is used to send/receive the policy info. Now, go below the function LocalConnect() and make a new function called PolicyConnect(). I started by copying the LocalConnect() function and modifying it as needed. Here is what i came up with:
Code:
private void PolicyConnect(IAsyncResult ar)
{
	PluginUtils.ProtectedInvoke(() =>
	{
		TcpClient policyClient = _policyListener.EndAcceptTcpClient(ar);

		PluginUtils.Log("PolicyListener", "PolicyClient connected.");

		NetworkStream stream = policyClient.GetStream();
		StreamReader read = new StreamReader(stream, Encoding.UTF8);
		StreamWriter write = new StreamWriter(stream, Encoding.UTF8);


		string msg = "";
		char[] data = new char[256];
		int bytes = read.ReadBlock(data, 0, data.Length);
		msg = new string(data);

		PluginUtils.Log("PolicyListener", "Received: " + msg);
		if (msg.Contains("policy"))
		{
			write.Write("<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>\0");
			write.Flush();
		}

		read.Close();
		write.Close();
		stream.Close();
		policyClient.Close();

				
	}, "PolicyConnect", typeof(ObjectDisposedException));

	PluginUtils.ProtectedInvoke(() =>
	{
		if (_policyListener != null) _policyListener.BeginAcceptTcpClient(PolicyConnect, null);
	}, "PolicyListenerBeginListen");
}
Then try to compile and run it. I made these changes and ran it and it didnt cause the program to not work, so thats good. I cant say if this will work for you or not since i never had the issue you are having. But this should be close to the right solution. Hopefully if this doesnt work then someone with better C# knowledge can jump in and fix it so it does work for you. If this does work for you then let me know so i can get my code updated and posted so everyone else with this problem can use it.

Hope this works, or at least is on the right track.
Alright thank you so much for your time, I'll attempt this when I get home.
Quote Originally Posted by toddddd View Post
Ah gotcha, though you said the program only crashed when you stopped the proxy, meaning it runs fine until then.

Anyways ive been looking at the thread that PKTINOS posted as well as searching the forums for more answers. I really cant give you a reason why, but sounds like what they are saying is that flash is sending a "<policy-file-request/>" and the proxy has to reply with the correct cross-domain-policy xml. Im not sure why this isnt something built into k-relay already. I also dont really understand why it is doing this for some people but not everyone.

<...>
Nice answer. If it doesn't work for OP, I wonder if this request is something ignorable. When KRelay receives it, I think it tries to parse it as a packet. So you should be able to check the received data, see if it contains the word "policy" in the bytes, and if it does, ignore it.

Since it tries to use a packetreader on the new data, thinking it's a packet while it's not.

So convert the byte[] to char[], to string, then check for the word "policy", if true "return;"

Assuming you can still connect after it's ignored, without responding, you should be fine.
Quote Originally Posted by New View Post


Nice answer. If it doesn't work for OP, I wonder if this request is something ignorable. When KRelay receives it, I think it tries to parse it as a packet. So you should be able to check the received data, see if it contains the word "policy" in the bytes, and if it does, ignore it.

Since it tries to use a packetreader on the new data, thinking it's a packet while it's not.

So convert the byte[] to char[], to string, then check for the word "policy", if true "return;"

Assuming you can still connect after it's ignored, without responding, you should be fine.
Yeah thats something i was wondering as well. From what i read it almost sounds like the flash application will refuse to connect if it doesnt get the right answer back from the request, but i could be wrong. But yeah im pretty sure you are right that the problem thats arising for everyone is that k-relay is attempting to parse the data as a regular packet when really it isnt. Hopefully either the method i posted works or someone can come up with the right answer on all this.
Well, I haven't tried that code yet, however. I booted into a server with KRelay opened then changed to Proxy, and connected fine.

Thoughts?
Quote Originally Posted by Alt_World View Post
Well, I haven't tried that code yet, however. I booted into a server with KRelay opened then changed to Proxy, and connected fine.

Thoughts?
yes thats one of the things i suggested earlier. The swf will send out the "policy" request to whichever server it connects to first, it only needs to do this once. So by connecting to a regular rotmg server first, the swf is getting the correct "cross-domain" response (which it only needs to do once). Then when you go to connect to the proxy it wont have to send/request that info again.
Thank you everyone. Solved.
Good to hear it was solved

Close @059 @Ahl
Posts 115 of 17 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?