boorik / smartfox-haxe-client Goto Github PK
View Code? Open in Web Editor NEWhaxe openfl client for smartfoxserver
License: MIT License
haxe openfl client for smartfoxserver
License: MIT License
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)
When setting a Zone to "Use Encryption" and attempting to connect, the client crashes.
Client code:
// SmartFox connection
var sfs:SmartFox;
...
// Event listener
sfs.addEventListener(SFSEvent.CRYPTO_INIT, onCryptoInit);
...
// Calling initCrypto to trigger "onCryptoInit" event listener
sfs.initCrypto();
...
// Login to Zone
private function onCryptoInit(evt:SFSEvent)
{
if (evt.params.success)
sfs.send(new LoginRequest("username", "password", sfs.config.zone));
}
The problem is that using cast
to convert an openfl or flash ByteArray to a crypto ByteArray results in a null value. For example, in the encrypt
function in DefaultPacketEncrypter
, Crypto.getCipher(ALGORITHM, cast ck.key, cast padding);
causes a crash because the ck.key
cast results in a null.
Called from hxcpp::__hxcpp_main
Called from ApplicationMain::main ApplicationMain.hx line 25
Called from ApplicationMain::create ApplicationMain.hx line 130
Called from lime.app.Application::exec lime/app/Application.hx line 150
Called from lime._internal.backend.native.NativeApplication::exec lime/_internal/backend/native/NativeApplication.hx line 146
Called from lime._internal.backend.native.NativeApplication::handleApplicationEvent lime/_internal/backend/native/NativeApplication.hx line 175
Called from lime.app._Event_Int_Void::dispatch lime/_internal/macros/EventMacro.hx line 91
Called from lime.system.ThreadPool::__update lime/system/ThreadPool.hx line 185
Called from lime.app._Event_Dynamic_Void::dispatch lime/_internal/macros/EventMacro.hx line 91
Called from lime._internal.backend.native.NativeHTTPRequest::multiThreadPool_onProgress lime/_internal/backend/native/NativeHTTPRequest.hx line 570
Called from lime.app.Promise_haxe_io_Bytes::complete lime/app/Promise.hx line 108
Called from lime._internal.backend.native.NativeHTTPRequest::loadText lime/_internal/backend/native/NativeHTTPRequest.hx line 349
Called from lime.app.Promise_String::complete lime/app/Promise.hx line 108
Called from lime.net._HTTPRequest_String::load lime/net/HTTPRequest.hx line 146
Called from lime.app.Promise::complete lime/app/Promise.hx line 108
Called from openfl.net.URLLoader::load openfl/net/URLLoader.hx line 318
Called from openfl.events.EventDispatcher::dispatchEvent openfl/events/EventDispatcher.hx line 246
Called from openfl.events.EventDispatcher::__dispatchEvent openfl/events/EventDispatcher.hx line 402
Called from com.smartfoxserver.v2.util.CryptoInitializer::onHttpResponse com/smartfoxserver/v2/util/CryptoInitializer.hx line 85
Called from openfl.events.EventDispatcher::dispatchEvent openfl/events/EventDispatcher.hx line 246
Called from openfl.events.EventDispatcher::__dispatchEvent openfl/events/EventDispatcher.hx line 402
Called from TitleState::onCryptoInit TitleState.hx line 298
Called from TitleState::selectLogin TitleState.hx line 280
Called from TitleState::sendLogin TitleState.hx line 226
Called from com.smartfoxserver.v2.SmartFox::send com/smartfoxserver/v2/SmartFox.hx line 1888
Error : Null Object Reference
I tried to compile for Android , but in SFSObject.hx is missing putText(...) .
It's available in AS3 and javascript ( at example : http://docs2x.smartfoxserver.com/api-docs/asdoc/ )
Would be possible to add missing putText(...) ? I'm not sure how pass restriction with max length: 2 GBytes.
Hi boorik,
is the bluebox protocol currently supported? In our tests it looks like it's not working, but I wanted to check first before we start diving into building it ourselves. Our games are live now with the API and we have a few user complaints that they can not play anymore.
Thanks,
Ruben
Hello,
when compiling the library with Air for iOS (Objective C, not interpreter), the function SFSArray::getBool is always returning null at the moment.
This is the original line that causes a problem:
return(wrapper != null ?cast(wrapper.data,Bool):null);
I was testing a bit and this is the easiest way to fix it:
return(wrapper != null ?cast(wrapper.data):null);
I can prepare a pull request, do you have any concerns or another preferred fix?
Just a sidenote: iOS with Air builds have some of these mystery bugs from time to time, due to the fact that the compilation works differently on the platform (no AVM). We have seen some rare and strange issues in AS3 code on iOS as well, before we started using Haxe.
When connected on Android, the app doesn't properly fire the SFSEvent.CONNECTION_LOST
when the connection to the server is lost. HTML5, Windows, macOS and even iOS do not exhibit this issue.
In this example, I manually shut down the server, but the closed socket event isn't read. The client continually keeps running, repeatedly spitting out the following:
com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx:556: ## SocketError:[IOErrorEvent type="ioError" bubbles=true cancelable=false text="Operation attempted on invalid socket." errorID=0]
I tried listening for a SFSEvent.SOCKET_ERROR
, but nothing fires for that either, although that may be by design.
SFSDataSerializer not works correctly (at example object2binary(...) ). I tried to check documentation http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/index.html ,but link for SFSDataSerializer are broken. Should I exposed HTML5 methods or need to rewrite the DefaultSFSDataSerializer class ?
Hi ,
Is HTML5 support still in progress ? What is the current status of the html5 target?
Hello,
we are seeing this exception when trying to use the SFS2X Haxe API. Is this a known issue, maybe an incompatibility to the latest Haxe version?
Thanks in advance,
Ruben
`[Fault] exception, information=ReferenceError: Error #1069: Property iterator not found on haxe.ds.IntMap and there is no default value.
Lambda$/array at C:\HaxeToolkit\haxe\std\Lambda.hx:46
com.smartfoxserver.v2.entities.managers::SFSUserManager/getUserList at O:\wd\SFS2X_AS3_API_source\src\com\smartfoxserver\v2\entities\managers\SFSUserManager.as:120
com.smartfoxserver.v2.entities::SFSRoom/get userList at O:\wd\SFS2X_AS3_API_source\src\com\smartfoxserver\v2\entities\SFSRoom.as:359
com.smartfoxserver.v2.controllers::SystemController/fnRoomLost at O:\wd\SFS2X_AS3_API_source\src\com\smartfoxserver\v2\controllers\SystemController.as:389
com.smartfoxserver.v2.controllers::SystemController/handleMessage at O:\wd\SFS2X_AS3_API_source\src\com\smartfoxserver\v2\controllers\SystemController.as:139
com.smartfoxserver.v2.core::SFSProtocolCodec/dispatchRequest at O:\wd\SFS2X_AS3_API_source\src\com\smartfoxserver\v2\core\SFSProtocolCodec.as:150
com.smartfoxserver.v2.core::SFSProtocolCodec/onPacketRead at O:\wd\SFS2X_AS3_API_source\src\com\smartfoxserver\v2\core\SFSProtocolCodec.as:54
com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData at O:\wd\SFS2X_AS3_API_source\src\com\smartfoxserver\v2\core\SFSIOHandler.as:252
com.smartfoxserver.v2.core::SFSIOHandler/onDataRead at O:\wd\SFS2X_AS3_API_source\src\com\smartfoxserver\v2\core\SFSIOHandler.as:111
com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData at O:\wd\SFS2X_AS3_API_source\src\com\smartfoxserver\v2\bitswarm\BitSwarmClient.as:454`
Hi,
what do you think of removing the interfaces ISFSArray and ISFSObject and instead declaring all functions with SFSArray and SFSObject?
This would improve the constistency with the HTML5 API because in Javascript there are no interfaces. This causes incompatibilities between the HTML5 and all other targets where for example SFSObject.getSFSArray() returns an instance of SFSArray in HTML5 and an instance of ISFSArray on all other targets.
I do not expect any errors or problems from this change. If you agree I could create a merge request in the next days.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.