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

Server communication #1

Closed
sofiane-soufi opened this issue Mar 16, 2017 · 1 comment
Closed

Server communication #1

sofiane-soufi opened this issue Mar 16, 2017 · 1 comment

Comments

@sofiane-soufi
Copy link

sofiane-soufi commented Mar 16, 2017

Hi again,

I'm having some problems creating a base server to read the login credentials from the client you made. Here's my code:

HaxeExtension.hx

`package;

import java.Lib;
import com.smartfoxserver.v2.extensions.SFSExtension;
import com.smartfoxserver.v2.extensions.ExtensionLogLevel;
import com.smartfoxserver.v2.core.SFSEventType;

@:nativeGen
class HaxeExtension extends SFSExtension
{
@:overload override public function init()
{
this.log("Extension started");

	this.addEventHandler(SFSEventType.USER_LOGIN, cast(UserLogin, java.lang.Class<Dynamic>));
}

public function log(obj:Dynamic):Void
{
	this.trace(ExtensionLogLevel.WARN, java.NativeArray.make(Std.string(obj) ));
}	

}`

UserLogin.hx

`package;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseServerEventHandler;
import com.smartfoxserver.v2.extensions.ExtensionLogLevel;

@:nativeGen
class UserLogin extends BaseServerEventHandler
{

@:overload
override public function handleServerEvent(event:ISFSEvent):Void
{
	var credentials:SFSObject = event.getParameter(cast SFSEventParam.LOGIN_IN_DATA);
	var user:User = event.getParameter(cast SFSEventParam.USER);
	this.trace(ExtensionLogLevel.WARN, java.NativeArray.make(user.getName()+" joined the game with the sid: "+credentials.getUtfString("sid")));
}

}`

Here's what I get in the logs:

16 Mar 2017 | 12:06:21,368 | INFO | SocketReader | bitswarm.sessions.DefaultSessionManager | | Session created: { Id: 3, Type: DEFAULT, Logged: No, IP: 0 } on Server port: 9933 <---> 0
16 Mar 2017 | 12:06:21,432 | WARN | SFSWorker:Ext:3 | entities.managers.SFSExtensionManager | | java.lang.NullPointerException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: Error during event handling: java.lang.NullPointerException, Listener: { Ext: HaxeExtension, Type: JAVA, Lev: ZONE, { Zone: Chapatiz }, {} }
+--- --- ---+
Stack Trace:
+--- --- ---+
haxe.root.UserLogin.handleServerEvent(UserLogin.java:22)
com.smartfoxserver.v2.extensions.SFSExtension.handleServerEvent(SFSExtension.java:259)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:768)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchZoneLevelEvent(SFSExtensionManager.java:689)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:886)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:65)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

@sofiane-soufi
Copy link
Author

Never mind!

Here's what I did to solve my problem:

HaxeExtension.hx

`package;

import java.Lib;
import com.smartfoxserver.v2.extensions.SFSExtension;
import com.smartfoxserver.v2.extensions.ExtensionLogLevel;
import com.smartfoxserver.v2.core.SFSEventType;

@:nativeGen
class HaxeExtension extends SFSExtension
{
@:overload override public function init()
{
this.log("Extension started");

	this.addEventHandler(SFSEventType.USER_LOGIN, cast(UserLogin, java.lang.Class<Dynamic>));
}

public function log(obj:Dynamic):Void
{
	this.trace(ExtensionLogLevel.WARN, java.NativeArray.make(Std.string(obj) ));
}	

}`

UserLogin.hx

`package;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseServerEventHandler;
import com.smartfoxserver.v2.extensions.ExtensionLogLevel;

@:nativeGen
class UserLogin extends BaseServerEventHandler
{

@:overload
override public function handleServerEvent(event:ISFSEvent):Void
{
	var user:String = event.getParameter(cast SFSEventParam.LOGIN_NAME);
	var params:SFSObject = event.getParameter(cast SFSEventParam.LOGIN_IN_DATA);
	var sid:String = params.getUtfString("sid");
	
	
	this.trace(ExtensionLogLevel.WARN, java.NativeArray.make(user+" joined the game with the sid : "+sid));
}

}`

@boorik boorik closed this as completed Jul 17, 2017
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