diff --git a/Client/export/windows/cpp/bin/SkullRush.exe b/Client/export/windows/cpp/bin/SkullRush.exe index 36dccfc..d2c5f95 100644 Binary files a/Client/export/windows/cpp/bin/SkullRush.exe and b/Client/export/windows/cpp/bin/SkullRush.exe differ diff --git a/Client/export/windows/cpp/bin/config.txt b/Client/export/windows/cpp/bin/config.txt index 4a1d623..acef89f 100644 --- a/Client/export/windows/cpp/bin/config.txt +++ b/Client/export/windows/cpp/bin/config.txt @@ -1,4 +1,4 @@ -version=0.3.6 +version=0.3.7 name=NOOB team=1 ip= diff --git a/Client/source/Downloader.hx b/Client/source/Downloader.hx index 3ec29d3..21628c7 100644 --- a/Client/source/Downloader.hx +++ b/Client/source/Downloader.hx @@ -52,7 +52,7 @@ class Downloader switch (event.type) { case LoaderEventType.Fail(error): - Reg.state.downloadError(error); + Reg.pre_state.downloadError(error); case LoaderEventType.Complete: //Start sub-manifest downloading @@ -88,7 +88,7 @@ class Downloader switch (event.type) { case LoaderEventType.Fail(error): - Reg.state.downloadError(error); + Reg.pre_state.downloadError(error); case LoaderEventType.Complete: @@ -203,7 +203,7 @@ class Downloader switch (event.type) { case LoaderEventType.Fail(error): - Reg.state.downloadError(error); + Reg.pre_state.downloadError(error); case LoaderEventType.Complete: diff --git a/Client/source/PlayState.hx b/Client/source/PlayState.hx index 9077199..51359b5 100644 --- a/Client/source/PlayState.hx +++ b/Client/source/PlayState.hx @@ -20,6 +20,7 @@ import flixel.util.FlxAngle; import flixel.util.FlxMath; import flixel.util.FlxPoint; import flixel.util.FlxRect; +import flixel.util.FlxTimer; import flixel.util.FlxVector; import haxe.io.Bytes; import haxe.macro.Expr.Function; @@ -53,7 +54,6 @@ class PlayState extends FlxState public var scores:NScoreManager; public var player:Player; - public var playermap:Map; public var ping_text:FlxText; public var teams:Array; @@ -68,13 +68,13 @@ class PlayState extends FlxState public var cross:FlxCrosshairs; - //public var buffer_string:String; + public var buffer_string:String; public function new(BufferString:String = null) { super(); - //buffer_string = BufferString; + buffer_string = BufferString; } /** @@ -82,7 +82,7 @@ class PlayState extends FlxState */ override public function create():Void { - SkullClient.initClient(); + //SkullClient.initClient(); persistentDraw = true; persistentUpdate = true; @@ -98,7 +98,7 @@ class PlayState extends FlxState super.create(); Reg.state = this; - playermap = new Map(); + //playermap = new Map(); background = new FlxGroup(); add(background); @@ -155,15 +155,42 @@ class PlayState extends FlxState //wepBar = new WeaponBar(2); //hud.add(wepBar); - Assets.initAssets(); - Thread.create(thread); + SkullClient.execute = true; + //Assets.initAssets(); + //Thread.create(thread); + //new FlxTimer(10, delayedThread); m = new Mutex(); //if (buffer_string != null) //{ - //loadMap("Test", buffer_string); + loadMap("Test", buffer_string); //} + + for (i in Reg.playermap.keys()) + { + var p:Player = Reg.playermap.get(i); + + var p_new:Player; + p_new = new Player(p.ID, p.name, 50, 50); + + Reg.playermap.set(i, p_new); + + if (p_new.ID == Reg.playerID) + { + Reg.state.player = p_new; + + FlxG.camera.follow(Reg.state.player); + FlxG.camera.followLerp = 30.0; + } + } + + new FlxTimer(5, delayedThread); + } + + public function delayedThread(T:FlxTimer):Void + { + Thread.create(thread); } public function sendChatMsg():Void @@ -199,17 +226,17 @@ class PlayState extends FlxState } } - public function onLoaded():Void - { - trace("Loaded external assets."); + //public function onLoaded():Void + //{ + //trace("Loaded external assets."); //if (buffer_string == null) //{ - Msg.PlayerInfo.data.set("name", Assets.config.get("name")); - Msg.PlayerInfo.data.set("team", Assets.config.get("team")); - - Reg.client.send(Msg.PlayerInfo.ID, 1, ENet.ENET_PACKET_FLAG_RELIABLE); + //Msg.PlayerInfo.data.set("name", Assets.config.get("name")); + //Msg.PlayerInfo.data.set("team", Assets.config.get("team")); + // + //Reg.client.send(Msg.PlayerInfo.ID, 1, ENet.ENET_PACKET_FLAG_RELIABLE); //} - } + //} public function loadMap(MapName:String, MapString:String):Void { @@ -284,7 +311,7 @@ class PlayState extends FlxState //trailArea.y = collidemap.y - FlxG.height / 2; //trailArea.setSize(collidemap.width + FlxG.width, collidemap.height + FlxG.height); - for (p in playermap.iterator()) + for (p in Reg.playermap.iterator()) { var pl:Player = p; @@ -306,23 +333,23 @@ class PlayState extends FlxState } } - public function downloadError(e:LoaderErrorType):Void - { - switch (e) - { - case LoaderErrorType.Data: - - - case LoaderErrorType.Format: - - - case LoaderErrorType.IO: - - - case LoaderErrorType.Security: - - } - } + //public function downloadError(e:LoaderErrorType):Void + //{ + //switch (e) + //{ + //case LoaderErrorType.Data: + // + // + //case LoaderErrorType.Format: + // + // + //case LoaderErrorType.IO: + // + // + //case LoaderErrorType.Security: + // + //} + //} /** * Function that is called when this state is destroyed - you might want to diff --git a/Client/source/Player.hx b/Client/source/Player.hx index 2b60f80..e48d69c 100644 --- a/Client/source/Player.hx +++ b/Client/source/Player.hx @@ -12,6 +12,7 @@ class Player extends PlayerBase public function new(Id:Int, Name:String, X:Int, Y:Int) { super(Id, Name, X, Y); + trace("newplayer"); setGun(1); } diff --git a/Client/source/PreGame.hx b/Client/source/PreGame.hx new file mode 100644 index 0000000..366819b --- /dev/null +++ b/Client/source/PreGame.hx @@ -0,0 +1,68 @@ +package ; +import flixel.FlxState; +import mloader.Loader.LoaderErrorType; +import enet.ENet; + +/** + * ... + * @author Ohmnivore + */ + +class PreGame extends FlxState +{ + + public function new() + { + super(); + } + + override public function create():Void + { + super.create(); + + Reg.pre_state = this; + Reg.playermap = new Map(); + + Assets.initAssets(); + + SkullClient.initClient(); + } + + public function onLoaded():Void + { + trace("Loaded external assets."); + //if (buffer_string == null) + //{ + Msg.PlayerInfo.data.set("name", Assets.config.get("name")); + Msg.PlayerInfo.data.set("team", Assets.config.get("team")); + + Reg.client.send(Msg.PlayerInfo.ID, 1, ENet.ENET_PACKET_FLAG_RELIABLE); + //} + } + + public function downloadError(e:LoaderErrorType):Void + { + switch (e) + { + case LoaderErrorType.Data: + + + case LoaderErrorType.Format: + + + case LoaderErrorType.IO: + + + case LoaderErrorType.Security: + + } + } + + override public function update():Void + { + super.update(); + + Reg.client.poll(); + } + +} \ No newline at end of file diff --git a/Client/source/SkullClient.hx b/Client/source/SkullClient.hx index faf70b1..5040684 100644 --- a/Client/source/SkullClient.hx +++ b/Client/source/SkullClient.hx @@ -42,6 +42,8 @@ class SkullClient extends Client public static var execute:Bool = false; public static var init:Bool = false; + private var old_msg:Int = -1; + public static function initClient():Void { if (!init) @@ -134,16 +136,20 @@ class SkullClient extends Client { super.onReceive(MsgID, E); + //if (old_msg != MsgID) + //trace(MsgID); + //old_msg = MsgID; + if (MsgID == Msg.Manifest.ID) { if (Msg.Manifest.data.get("url") == "null") { - Reg.state.onLoaded(); + Reg.pre_state.onLoaded(); } else { var d:Downloader = new Downloader(Msg.Manifest.data.get("url")); - d.whenfinished = Reg.state.onLoaded; + d.whenfinished = Reg.pre_state.onLoaded; } } @@ -151,8 +157,10 @@ class SkullClient extends Client { //if (Reg.state.collidemap != null) //FlxG.switchState(new PlayState()); - Reg.state.loadMap(Msg.MapMsg.data.get("mapname"), Msg.MapMsg.data.get("mapstring")); - //FlxG.switchState(new PlayState(Msg.MapMsg.data.get("mapstring"))); + //Reg.state.loadMap(Msg.MapMsg.data.get("mapname"), Msg.MapMsg.data.get("mapstring")); + //trace(Msg.MapMsg.data.get("mapstring")); + SkullClient.execute = false; + FlxG.switchState(new PlayState(Msg.MapMsg.data.get("mapstring"))); } if (MsgID == Msg.PlayerInfoBack.ID) @@ -162,10 +170,13 @@ class SkullClient extends Client 50, 50); + Reg.playerID = Reg.state.player.ID; + Reg.state.player.setColor(Msg.PlayerInfoBack.data.get("color"), Msg.PlayerInfoBack.data.get("graphic")); - Reg.state.playermap.set(Reg.state.player.ID, Reg.state.player); + //Reg.state.playermap.set(Reg.state.player.ID, Reg.state.player); + Reg.playermap.set(Reg.state.player.ID, Reg.state.player); FlxG.camera.follow(Reg.state.player); FlxG.camera.followLerp = 30.0; @@ -181,16 +192,19 @@ class SkullClient extends Client p.setColor(Msg.PlayerInfoAnnounce.data.get("color"), Msg.PlayerInfoAnnounce.data.get("graphic")); - Reg.state.playermap.set(p.ID, p); + //Reg.state.playermap.set(p.ID, p); + Reg.playermap.set(p.ID, p); } if (MsgID == Msg.PlayerDisco.ID) { - var p:Player = Reg.state.playermap.get(Msg.PlayerDisco.data.get("id")); + //var p:Player = Reg.state.playermap.get(Msg.PlayerDisco.data.get("id")); + var p:Player = Reg.playermap.get(Msg.PlayerDisco.data.get("id")); if (p != null) { - Reg.state.playermap.remove(Msg.PlayerDisco.data.get("id")); + //Reg.state.playermap.remove(Msg.PlayerDisco.data.get("id")); + Reg.playermap.remove(Msg.PlayerDisco.data.get("id")); p.kill(); } @@ -210,7 +224,8 @@ class SkullClient extends Client { if (parr[0] != null) { - var p:Player = Reg.state.playermap.get(parr[0]); + //var p:Player = Reg.state.playermap.get(parr[0]); + var p:Player = Reg.playermap.get(parr[0]); if (p != null) { @@ -502,7 +517,8 @@ class SkullClient extends Client if (MsgID == Msg.SetAppearance.ID) { - var p:Player = Reg.state.playermap.get(Msg.SetAppearance.data.get("id")); + //var p:Player = Reg.state.playermap.get(Msg.SetAppearance.data.get("id")); + var p:Player = Reg.playermap.get(Msg.SetAppearance.data.get("id")); if (p != null) { @@ -604,7 +620,8 @@ class SkullClient extends Client { NWeapon.addWeapon(new NWeapon(map.get(slot)), slot + 1); } - for (p in Reg.state.playermap.iterator()) + //for (p in Reg.state.playermap.iterator()) + for (p in Reg.playermap.iterator()) { p.guns_arr = []; NWeapon.setUpWeapons(p); diff --git a/Client/source/networkobj/NScoreboard.hx b/Client/source/networkobj/NScoreboard.hx index 006f623..e2986cb 100644 --- a/Client/source/networkobj/NScoreboard.hx +++ b/Client/source/networkobj/NScoreboard.hx @@ -142,7 +142,8 @@ class NScoreboard X = X_BORDER; - var t:FlxText = new FlxText(X, Y, FlxG.width, Reg.state.playermap.get(arrt[0]).name); + //var t:FlxText = new FlxText(X, Y, FlxG.width, Reg.state.playermap.get(arrt[0]).name); + var t:FlxText = new FlxText(X, Y, FlxG.width, Reg.playermap.get(arrt[0]).name); t_group.add(t); X += X_SPACING; diff --git a/Client/source/ui/Home.hx b/Client/source/ui/Home.hx index d3417ba..7f34594 100644 --- a/Client/source/ui/Home.hx +++ b/Client/source/ui/Home.hx @@ -92,7 +92,7 @@ class Home extends FlxUIState public function autoLaunch():Void { - FlxG.switchState(new PlayState()); + FlxG.switchState(new PreGame()); } public function openUpdate():Void diff --git a/Client/source/ui/Public.hx b/Client/source/ui/Public.hx index f7a3935..6650664 100644 --- a/Client/source/ui/Public.hx +++ b/Client/source/ui/Public.hx @@ -96,7 +96,7 @@ class Public extends FlxUIState var i:String = cast params[0]; Assets.config.set("ip", i); Assets.saveConfig(); - FlxG.switchState(new PlayState()); + FlxG.switchState(new PreGame()); } } } diff --git a/Client/source/ui/Util.hx b/Client/source/ui/Util.hx index 2bba94c..9731ba4 100644 --- a/Client/source/ui/Util.hx +++ b/Client/source/ui/Util.hx @@ -12,7 +12,7 @@ class Util static public function launchGame():Void { - FlxG.switchState(new PlayState()); + FlxG.switchState(new PreGame()); } static public function initXML(S:FlxUIState):Void diff --git a/README.md b/README.md index f128a10..29fb9f2 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@ At the moment the client source code is a mess. I'll clean it up one day. ## Bugs: * Fix annoying LAN server discovery bug -* Map change crash ## Assets: diff --git a/Server/export/windows/cpp/bin/SkullRushServer.exe b/Server/export/windows/cpp/bin/SkullRushServer.exe index d9a859d..16638e8 100644 Binary files a/Server/export/windows/cpp/bin/SkullRushServer.exe and b/Server/export/windows/cpp/bin/SkullRushServer.exe differ diff --git a/Server/export/windows/cpp/bin/config.txt b/Server/export/windows/cpp/bin/config.txt index fd8393a..3f69f58 100644 --- a/Server/export/windows/cpp/bin/config.txt +++ b/Server/export/windows/cpp/bin/config.txt @@ -1,4 +1,4 @@ -version=0.3.5 +version=0.3.7 ############################ diff --git a/Server/source/gamemodes/BOX.hx b/Server/source/gamemodes/BOX.hx index 4e1dfd4..61f39b8 100644 --- a/Server/source/gamemodes/BOX.hx +++ b/Server/source/gamemodes/BOX.hx @@ -188,7 +188,7 @@ class BOX extends BaseGamemode { var P:Player = E.player; super.initPlayer(E); - DefaultHooks.initPlayer(P); + DefaultHooks.initPlayer(P, E.firstInit); //score.addPlayer(Reg.server.playermap.get(P.ID)); } diff --git a/Server/source/gamemodes/CTF.hx b/Server/source/gamemodes/CTF.hx index 81a2c16..111afd9 100644 --- a/Server/source/gamemodes/CTF.hx +++ b/Server/source/gamemodes/CTF.hx @@ -211,7 +211,7 @@ class CTF extends BaseGamemode var P:Player = E.player; super.initPlayer(E); - DefaultHooks.initPlayer(P); + DefaultHooks.initPlayer(P, E.firstInit); score.addPlayer(Reg.server.playermap.get(P.ID)); captures.set(P.ID, 0); diff --git a/Server/source/gamemodes/DefaultHooks.hx b/Server/source/gamemodes/DefaultHooks.hx index a12690e..b7ef602 100644 --- a/Server/source/gamemodes/DefaultHooks.hx +++ b/Server/source/gamemodes/DefaultHooks.hx @@ -310,16 +310,6 @@ class DefaultHooks static public function preInitPlayer(P:Player):Void { - //NWeapon.announceWeapons(P.ID); - } - - static public function initPlayer(P:Player):Void - { - //Reg.server.sendMsg(P.ID, Msg.MapMsg.ID, 2, ENet.ENET_PACKET_FLAG_RELIABLE); - - NEmitter.announceEmitters(P.ID); - NWeapon.announceWeapons(P.ID); - Msg.AnnounceTemplates.data.set("serialized", NReg.exportTemplates()); Reg.server.sendMsg(P.ID, Msg.AnnounceTemplates.ID, 2, ENet.ENET_PACKET_FLAG_RELIABLE); @@ -352,6 +342,50 @@ class DefaultHooks Msg.Teams.data.set("serialized", Serializer.run(t_arr)); Reg.server.sendMsg(P.ID, Msg.Teams.ID, 2, ENet.ENET_PACKET_FLAG_RELIABLE); + NEmitter.announceEmitters(P.ID); + NWeapon.announceWeapons(P.ID); + } + + static public function initPlayer(P:Player, firstInit:Bool = false):Void + { + if (!firstInit) + { + Msg.AnnounceTemplates.data.set("serialized", NReg.exportTemplates()); + + Reg.server.sendMsg(P.ID, Msg.AnnounceTemplates.ID, 2, ENet.ENET_PACKET_FLAG_RELIABLE); + + for (s in NReg.sprites) + { + s.announce(P.ID); + } + + for (h in NReg.huds) + { + h.announce(P.ID); + } + + for (t in NReg.timers.iterator()) + { + t.announce(P.ID); + } + + for (s in BaseGamemode.scores.scores.iterator()) + { + s.announce(P.ID); + } + + var t_arr:Array = []; + for (t in Reg.gm.teams) + { + t_arr.push(t.serialize()); + } + Msg.Teams.data.set("serialized", Serializer.run(t_arr)); + Reg.server.sendMsg(P.ID, Msg.Teams.ID, 2, ENet.ENET_PACKET_FLAG_RELIABLE); + + NEmitter.announceEmitters(P.ID); + NWeapon.announceWeapons(P.ID); + } + P.health = 0; P.respawnIn(Reg.gm.spawn_time, 2); } @@ -386,7 +420,6 @@ class DefaultHooks Msg.PlayerInfoBack.data.set("color", p.header.color); Msg.PlayerInfoBack.data.set("graphic", p.graphicKey); - Reg.server.sendMsg(E.ID, Msg.MapMsg.ID, 1, ENet.ENET_PACKET_FLAG_RELIABLE); preInitPlayer(p); Reg.server.sendMsg(E.ID, Msg.PlayerInfoBack.ID, 1, ENet.ENET_PACKET_FLAG_RELIABLE); @@ -427,7 +460,7 @@ class DefaultHooks } } - Reg.gm.dispatchEvent(new InitEvent(InitEvent.INIT_EVENT, p)); + Reg.gm.dispatchEvent(new InitEvent(InitEvent.INIT_EVENT, p, true)); } static public function update(elapsed:Float):Void diff --git a/Server/source/gamemodes/FFA.hx b/Server/source/gamemodes/FFA.hx index b5db17f..899cd0a 100644 --- a/Server/source/gamemodes/FFA.hx +++ b/Server/source/gamemodes/FFA.hx @@ -182,7 +182,7 @@ class FFA extends BaseGamemode { var P:Player = E.player; super.initPlayer(E); - DefaultHooks.initPlayer(P); + DefaultHooks.initPlayer(P, E.firstInit); score.addPlayer(Reg.server.playermap.get(P.ID)); } diff --git a/Server/source/gamemodes/KOTH.hx b/Server/source/gamemodes/KOTH.hx index aa29e00..34df69f 100644 --- a/Server/source/gamemodes/KOTH.hx +++ b/Server/source/gamemodes/KOTH.hx @@ -172,7 +172,7 @@ class KOTH extends BaseGamemode { var P:Player = E.player; super.initPlayer(E); - DefaultHooks.initPlayer(P); + DefaultHooks.initPlayer(P, E.firstInit); //score.addPlayer(Reg.server.playermap.get(P.ID)); } diff --git a/Server/source/gevents/InitEvent.hx b/Server/source/gevents/InitEvent.hx index fab49f1..a754d95 100644 --- a/Server/source/gevents/InitEvent.hx +++ b/Server/source/gevents/InitEvent.hx @@ -10,11 +10,13 @@ class InitEvent extends Event public static inline var INIT_EVENT:String = "INIT_event"; public var player:Player; + public var firstInit:Bool; - public function new(type:String, player_:Player, bubbles:Bool=false, cancelable:Bool=false) + public function new(type:String, player_:Player, FirstInit:Bool = false, bubbles:Bool=false, cancelable:Bool=false) { super(type, bubbles, cancelable); player = player_; + firstInit = FirstInit; } public override function clone():Event diff --git a/Shared/code/Reg.hx b/Shared/code/Reg.hx index e440eb1..32f5804 100644 --- a/Shared/code/Reg.hx +++ b/Shared/code/Reg.hx @@ -22,6 +22,12 @@ class Reg * Static client reference */ static public var client:SkullClient; + + static public var pre_state:PreGame; + + static public var playermap:Map; + + static public var playerID:Int; #end #if SERVER diff --git a/Shared/code/enet/NetBase.hx b/Shared/code/enet/NetBase.hx index f07b048..1f26d86 100644 --- a/Shared/code/enet/NetBase.hx +++ b/Shared/code/enet/NetBase.hx @@ -1,4 +1,5 @@ package enet; +import haxe.CallStack; /** * ... @@ -87,12 +88,22 @@ class NetBase m.unserialize(res[1]); } - onReceive(res[0], e); + try + { + onReceive(res[0], e); + } + catch (E2:Dynamic) + { + trace("Error processing message, error message: ", E2); + trace(CallStack.toString(CallStack.exceptionStack())); + trace(CallStack.toString(CallStack.callStack())); + + } } - catch (e:Dynamic) + catch (E:Dynamic) { - trace("Error receiving message, content: ", e.message); + trace("Error receiving message, content: ", e.message, "Error message: ", E); } }