GithubHelp home page GithubHelp logo

smartfox-haxe-client's Introduction

SmartFoxServer 2X Haxe Client API

Haxe openfl translation of the as3 client for the Smartfox server http://www.smartfoxserver.com/

Tested on flash, windows, ios and android targets.

You can have a look at https://github.com/boorik/smartfox-haxe-fullstack to check a sample project that use the api and haxe all the way.

Pull requests are welcome

Let me know how it works on other targets

Haxe OpenFL translation of the as3 client for the Smartfox server http://www.smartfoxserver.com/

CURRENTLY WORKING WITH :

haxe: 4.0.5

lime: 7.6.3

openfl: 8.9.5

haxe-crypto: 0.0.7

haxe-ws: 1.0.5


Instructions:

Installation

haxelib git smartfox-haxe-client https://github.com/boorik/smartfox-haxe-client

add in your project.xml :

<haxelib name="smartfox-haxe-client"/>

Then you can use it like the as3 api, check the as3 exemples there :
http://docs2x.smartfoxserver.com/ExamplesFlash/introduction

TODO:

  • test app
  • improve typing
  • make it framework agnostic pure haxe without openfl dependency
  • make it work with html5 target

smartfox-haxe-client's People

Contributors

barisyild avatar boorik avatar dpomier avatar flashultra avatar m0rkeulv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smartfox-haxe-client's Issues

Bluebox

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

SFSArray:getBool returning null on iOS (+ suggested fix)

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.

HTML5 support ?

Hi ,
Is HTML5 support still in progress ? What is the current status of the html5 target?

Crash when using encryption (null ByteArray cast)

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

Suggestion: Remove ISFSArray, ISFSObject

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.

Property iterator not found on haxe.ds.IntMap

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`

Server communication

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)

Android does not receive CONNECTION_LOST event

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.