Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event body wrong parsed #31

Open
SebastianVargas opened this issue Jun 7, 2018 · 1 comment
Open

Event body wrong parsed #31

SebastianVargas opened this issue Jun 7, 2018 · 1 comment

Comments

@SebastianVargas
Copy link

SebastianVargas commented Jun 7, 2018

When the event data contains ", " the parse fails. Because is looking for ", " to split it and get eventName and evenData.

If I set on Socket.cs in line 322

pkt.body = "["gameFinished",{"message":"Good job!, play in the new tournament"}]";

Will cause Warning message: gameFinished",{"message":"Good job event doesn't have a handler, because is taking gameFinished",{"message":"Good job as the eventName

Most robust way to separate even name and data should be implemented.

@SebastianVargas SebastianVargas changed the title Event body bad parsed Event body wrong parsed Jun 7, 2018
@sfranzyshen
Copy link

Event body parsed poorly (say that 10 times fast) the way I figure ... testing for a comma followed by a space was a way to prevent the data string from having a leading space ... why not keep it simple and trim off any leading spaces and leave the data string properly intact (i mean comma space is commonly used!) here is a snippet;

case SocketPacketTypes.EVENT:
	if (!pkt.HasBody) {
		Debug.LogWarningFormat("{0} has no body(data)", pkt.ToString());
		return;
	}

	var seperateIndex = pkt.body.IndexOf(',');
	var seperatorLen = 1;

	var eventName = pkt.body.Substring(2, seperateIndex - 3);
	if (!_handlers.ContainsKey(eventName)) {
		Debug.LogWarningFormat("{0} event doesn't have a handler", eventName);
		break;
	}

	var data = pkt.body.Substring(seperateIndex + seperatorLen, pkt.body.Length - seperateIndex - seperatorLen - 1).TrimStart();
	_handlers[eventName](data);
	break;

additionally I'm running this on ... socket.io 2.1.1 and unity 2017.4.14f1 #2 Support socket.io v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants