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

Add dominax + fix autologin on subscribe #57

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RewriteEngine on
RewriteCond $1 !^(index\.php|css|img|js|game|robots\.txt)
RewriteRule ^(.*)$ /Dominax/bin/php/index.php/$1 [L]
4 changes: 4 additions & 0 deletions assets/js/swfobject.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions dominax.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@
-neko bin/neko/index.n
-main Main
-D target=neko

--next

-cp dominax
-lib session
-lib beluga
-lib tink_macro
-neko bin/server.n
-main net.Server
-D target=neko
65 changes: 65 additions & 0 deletions dominax/Project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<app title="Dominax" file="dominax" main="Main" version="0.0.1" company="Beluga" />

<window width="640" height="480" fps="60" orientation="portrait" resizable="true" if="web" />
<window width="640" height="480" fps="60" orientation="landscape" fullscreen="false" hardware="true" vsync="true" unless="web" />

<!--The flixel preloader gets stuck in Chrome, so it's disabled by default for now.
Safe to use if you embed the swf into a html file!-->
<!--<app preloader="flixel.system.FlxPreloader" />-->

<!--The swf version should be at least 11.2 if you want to use the FLX_MOUSE_ADVANCED option-->
<set name="SWF_VERSION" value="11.8" />

<set name="BUILD_DIR" value="../bin/dominax" />
<classpath name="source" />

<haxedef name="network-sandbox" />

<!--You can use rename="newName" to shorten the paths to the individual subdirectories!-->
<assets path="assets" />
<assets path="assets/images" rename="images" include="*.jpg|*.png" />
<assets path="assets/data" rename="data" include="*.csv|*.pyxel" />
<assets path="assets/sounds" rename="sounds" include="*.wav" />

<haxelib name="flixel"/>

<!--In case you want to use the addons package-->
<haxelib name="flixel-addons" />

<!--In case you want to use the ui package-->
<!--<haxelib name="flixel-ui"/>-->

<!--In case you want to use nape with flixel-->
<!--<haxelib name="nape" />-->
<!--Enable this for nape release builds for a serious peformance improvement-->
<!--<haxedef name="NAPE_RELEASE_BUILD" />-->

<!--Enable experimental threading support for cpp targets-->
<!--<haxedef name="FLX_THREADING" />-->

<!--Enable the flixel core recording system-->
<!--<haxedef name="FLX_RECORD" />-->

<!--Enable right and middle click support for the mouse. Flash player version 11.2+, no HTML5 support -->
<!--<haxedef name="FLX_MOUSE_ADVANCED" />-->

<!--Disable the Native cursor api for Flash target-->
<!-- <haxedef name="FLX_NO_NATIVE_CURSOR" /> -->

<!--Optimise inputs, be careful you will get null errors if you don't use conditionals in your game-->
<!--<haxedef name="FLX_NO_MOUSE" if="mobile" />-->
<!--<haxedef name="FLX_NO_KEYBOARD" if="mobile" />-->
<!--<haxedef name="FLX_NO_TOUCH" if="desktop" />-->
<!--<haxedef name="FLX_NO_GAMEPAD" />-->

<!--Disable the Flixel core sound tray-->
<!--<haxedef name="FLX_NO_SOUND_TRAY" />-->

<!--Disable the Flixel core focus lost screen-->
<!--<haxedef name="FLX_NO_FOCUS_LOST_SCREEN" />-->

<!--Disable the Flixel core debugger. Automatically gets set whenever you compile in release mode!-->
<haxedef name="FLX_NO_DEBUG" unless="debug" />
</project>
Binary file added dominax/assets/images/classic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dominax/assets/images/classic.pyxel
Binary file not shown.
Binary file added dominax/assets/images/classic2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dominax/assets/images/classic2.pyxel
Binary file not shown.
14 changes: 14 additions & 0 deletions dominax/net/ClientApi.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net;

/**
* ...
* @author Masadow
*/
class ClientApi implements IClientApi
{
public function new () { }

public function logged() {
// display("User join <b>"+name+"</b>");
}
}
10 changes: 10 additions & 0 deletions dominax/net/IClientApi.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net;

/**
* ...
* @author Masadow
*/
interface IClientApi
{
public function logged() : Void;
}
10 changes: 10 additions & 0 deletions dominax/net/IServerApi.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net;

/**
* ...
* @author Masadow
*/
interface IServerApi
{
public function login(id : Int) : { id : Int, name : String };
}
59 changes: 59 additions & 0 deletions dominax/net/Server.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package net;

/**
* ...
* @author Masadow
*/
// define a typed remoting API
class ClientApiImpl extends haxe.remoting.AsyncProxy<net.IClientApi> {
}

// our client class
class ClientData extends ServerApi {

var api : ClientApiImpl;
var name : String;

public function new( scnx : haxe.remoting.SocketConnection ) {
api = new ClientApiImpl(scnx.client);
(cast scnx).__private = this;
}

public function leave() {
Server.clients.remove(this);
}

public static function ofConnection( scnx : haxe.remoting.SocketConnection ) : ClientData {
return (cast scnx).__private;
}

}

// server loop

class Server {

public static var clients = new List<ClientData>();

static function initClientApi( scnx : haxe.remoting.SocketConnection, context : haxe.remoting.Context ) {
trace("Client connected");
scnx.setErrorHandler(function (error) { trace(error); } );
var c = new ClientData(scnx);
context.addObject("api", c);
}

static function onClientDisconnected( scnx ) {
trace("Client disconnected");
ClientData.ofConnection(scnx).leave();
}

static function main() {
var host = "localhost";
var domains = [host];
var s = new neko.net.ThreadRemotingServer(domains);
s.initClientApi = initClientApi;
s.clientDisconnected = onClientDisconnected;
trace("Starting server...");
s.run(host,3000);
}
}
20 changes: 20 additions & 0 deletions dominax/net/ServerApi.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net;

import beluga.core.Beluga;
import beluga.module.account.Account;

/**
* ...
* @author Masadow
*/
class ServerApi implements IServerApi
{
public function login(id : Int)
{
Sys.println("Login attempt");
var acc = Beluga.getInstance().getModuleInstance(Account);
var usr = acc.getUser(id);
Sys.println("Return " + (usr != null ? usr.login : "null"));
return usr != null ? {id: usr.id, name: usr.login} : null;
}
}
90 changes: 90 additions & 0 deletions dominax/net/ServerCpp.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package ;
import haxe.ds.StringMap.StringMap;
import haxe.remoting.SocketProtocol.Socket;
#if (php || neko)
import haxe.Session;
#end
import sys.net.Host;
import haxe.web.Dispatch;

/**
* ...
* @author Masadow
*/
class Server
{

public function new()
{
}

public static function main()
{
var host : String = "localhost";
var port : String = "3000";
var args : Array<String> = Sys.args();
if (args.length == 2) {
host = args[0];
port = args[1];
}

var ctx = new haxe.remoting.Context();
ctx.addObject("Server", new ServerCppApi());
var server = new Socket();
server.bind(new Host(host), Std.parseInt(port));
server.listen(100);
var policyserver = new XmlPolicyServer(host);
var clients : Array<Socket> = [server, policyserver.socket];

Sys.println("Server running on " + host + ":" + port);
while (true)
{
for (socket in Socket.select(clients, [], []).read) //Retrieve ready sockets to read
{
trace("Incomming request");
// if ((untyped socket.__client) == null)
if (socket == server)
{
trace("Incomming connection");
//Incomming connection
var s = server.accept();
clients.push(s);
// var response = '<cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>\x00';
// s.write(response);
s.output.writeByte(1);
trace("Client connected");
}
else if (socket == policyserver.socket)
{
policyserver.update();
}
else
{
trace("Incomming message");
//Receiving client request
try {
var l = socket.input.readLine();
trace("Data : " + l);
var nparams = Std.parseInt(l);
Sys.println("params : " + nparams);
var request = socket.input.readLine();
var params = new StringMap<String>();
for (i in 0...nparams)
params.set("" + i, socket.input.readLine());
Dispatch.run(request, params, new ServerCppApi());
}
catch (e : Dynamic)
{
//Close socket
clients.remove(socket);
socket.close();
trace("Client disconnected");
}
trace("Message treated");
}
}
// client = server.accept();
}
// socket.
}
}
26 changes: 26 additions & 0 deletions dominax/net/ServerCppApi.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ;

import beluga.module.account.Account;
import beluga.core.Beluga;
import haxe.web.Dispatch;

/**
* ...
* @author Masadow
*/
class ServerCppApi
{

public function new()
{
}

public function doLogin(id : Int)
{
Sys.println("Login attempt");
var acc = Beluga.getInstance().getModuleInstance(Account);
var usr = acc.getUser(id);
return usr != null ? {id: usr.id, name: usr.login} : null;
}

}
66 changes: 66 additions & 0 deletions dominax/net/XmlPolicyServer.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package ;

import sys.net.Socket;
import sys.net.Host;
import haxe.io.Bytes;
/**
* Compiled separatly under neko.
*/

class XmlPolicyServer {
public var socket : Socket;

public function new(host : String) {
socket = new Socket();
try{
socket.bind( new Host( host ), 843 );

socket.listen( 10 );
}
catch (z:Dynamic) {
Sys.stdout().writeString("Server Start Failed. \n");
return;
}
Sys.println("Policy server running on " + host + ":843");
//while (true) {
//}
}

public function update()
{
trace("Receive policy request");
var cnx = socket.accept();
var tbuf = Bytes.alloc(30);
var cont = true;
var msg : String = '';
while (cont)
{
try
{
cnx.waitForRead();
var len = cnx.input.readBytes(tbuf, 0, 30);
msg += tbuf.toString().substr(0, len);
cont = msg.indexOf('\x00') < 0; // read up to null byte
}
catch (e : Dynamic)
{

var x = Std.string(e);
if (x != 'Eof')
{
trace('Error: $x');
}
cont = false;

}
}
var msg_cut = msg.substr(1, 6);

if ( msg_cut == 'policy' ) {
var response = '<cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>\x00';
cnx.write(response);
trace("Allow policy");
}
cnx.shutdown(true, true);
}
}
Loading