We've been using SFS on our next game for a few months now and it's amazing. We've found the answers to every problem we faced so far in this forum so thanks, Lapo!
We're now working on handling kicking for inactivity. When a client is disconnected (SFSEvent.CONNECTION_LOST), it goes back to the log in screen, gets a "You were disconnected for [reason]" window and is allowed to log in again. This works perfectly.
The problem is when the client tries to log in again, it gets no response from the server. No success, no failure. Nothing happens.
We checked the server log and
Code: Select all
java.lang.IllegalStateException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.IllegalStateException
Message: Session does not support encryption: { Id: 90, Type: DEFAULT, Logged: No, IP: 190.1.35.234:51495 }
Sender: { Id: 90, Type: DEFAULT, Logged: No, IP: 190.1.35.234:51495 }
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.protocol.binary.DefaultPacketEncrypter.execute(DefaultPacketEncrypter.java:42)
com.smartfoxserver.v2.protocol.binary.DefaultPacketEncrypter.decrypt(DefaultPacketEncrypter.java:22)
com.smartfoxserver.v2.protocol.binary.BinaryIoHandler.handlePacketData(BinaryIoHandler.java:410)
com.smartfoxserver.v2.protocol.binary.BinaryIoHandler.handleRead(BinaryIoHandler.java:197)
com.smartfoxserver.v2.protocol.SFSIoHandler.onDataRead(SFSIoHandler.java:143)
com.smartfoxserver.bitswarm.core.SocketReader.readTcpData(SocketReader.java:336)
com.smartfoxserver.bitswarm.core.SocketReader.readIncomingSocketData(SocketReader.java:220)
com.smartfoxserver.bitswarm.core.SocketReader.run(SocketReader.java:171)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
I googled this error a lot and saw it was related to InitCrypto().
This is our code around InitCrypto()
Code: Select all
public OnConnection(ServerClient client, ConnectionData data) : base(client, data)
{
client.AddEventListener(SFSEvent.CONNECTION, Content);
}
/**
* Sends a login request to the server right after the connection.
*/
protected override void Content(BaseEvent evt)
{
bool success = (bool) evt.Params["success"];
Debug.Log($"Success: {success}");
if (success)
{
Debug.Log("SFS2X API version: " + client.version);
Debug.Log("Connection mode is: " + client.connectionMode);
#if !UNITY_WEBGL
// Enable protocol encryption on non-WebGL builds only (WebGL build uses WSS protocol already)
if (_connectionData.useEncryption)
{
Debug.Log("Init crypto");
client.GetServer().InitCrypto();
}
else
{
client.SendRequest(new LoginRequest(_connectionData.GetUserName()));
}
#else
// Attempt login
client.SendRequest(new LoginRequest(_connectionData.GetUserName()));
#endif
}
else
{
Debug.Log("Something went wrong");
client.Dispose();
}
}
The Content() method is never called. I made sure SFSEvent.CONNECTION listener is never removed!
Any ideas? Thanks