public ChatServer(ISceneHost scene) { _scene = scene; _env = _scene.GetComponent<IEnvironment>(); _scene.AddProcedure("GetUsersInfos", OnGetUsersInfos); _scene.AddRoute("UpdateInfo", OnUpdateInfo); _scene.AddRoute("chat", OnMessageReceived); _scene.Connected.Add(OnConnected); _scene.Disconnected.Add(OnDisconnected); }
public void Init(ISceneHost scene) { _scene = scene; _env = _scene.GetComponent<IEnvironment>(); _log = _scene.GetComponent<ILogger>(); _scene.AddProcedure("RegisterObject", OnRegisterObject); _scene.AddRoute("RemoveObject", OnRemoveObject); _scene.AddRoute("UpdateSynchedObject", OnUpdateObject); _scene.Connected.Add(OnClientConnected); _scene.Disconnected.Add(OnClientDisconnected); }
public StickyPlatformsServer(ISceneHost scene) { mScene = scene; scene.AddProcedure("joinGame", joinGameProcedure); scene.AddProcedure("getPlayerList", ctx => { ctx.SendValue(mPlayers.Values.Where(player => player.hp > 0)); return(Task.FromResult(true)); }); scene.Disconnected.Add(onDisconnect); scene.AddRoute("spawn", onPlayerSpawn, _ => _); scene.AddRoute("updateHp", updateHp, _ => _); scene.AddRoute("updatePhysics", updatePhysics, _ => _); scene.AddRoute("updateKeys", updateKeys, _ => _); }
public void RegisterControllers() { var type = typeof(T); foreach (var method in type.GetMethods()) { var procedureName = GetProcedureName(type, method); if (IsRawAction(method)) { var ctxParam = Expression.Parameter(typeof(RequestContext <IScenePeerClient>), "ctx"); var controllerParam = Expression.Parameter(typeof(T), "controller"); var callExpr = Expression.Call(controllerParam, method, ctxParam); var action = Expression.Lambda <Func <T, RequestContext <IScenePeerClient>, Task> >(callExpr, controllerParam, ctxParam).Compile(); _scene.AddProcedure(procedureName, ctx => ExecuteRpcAction(ctx, action, procedureName)); } else if (IsRawRoute(method)) { var ctxParam = Expression.Parameter(typeof(Packet <IScenePeerClient>), "ctx"); var controllerParam = Expression.Parameter(typeof(T), "controller"); var callExpr = Expression.Call(controllerParam, method, ctxParam); var action = Expression.Lambda <Func <T, Packet <IScenePeerClient>, Task> >(callExpr, controllerParam, ctxParam).Compile(); _scene.AddRoute(procedureName, packet => ExecuteRouteAction(packet, action, procedureName), _ => _); } } }
// "main" scene constructor. The constructor is called by the server when the scene is created. // public Main(ISceneHost scene) { _scene = scene; _env = _scene.GetComponent<IEnvironment>(); _log = _scene.GetComponent<ILogger>(); _log.Debug("server", "starting configuration"); // we configure the functions that will be called by the Connecting, Connected and Disconnected events. // Connecting is called when a client tries to connect to the server. Please use this event to prevent player form accessing the server. // Connected is called when a client is already connected. // Disconnected is called when a client is already disconnected. _scene.Connecting.Add(OnConnecting); _scene.Connected.Add(OnConnected); _scene.Disconnected.Add(OnDisconnect); // We configure the routes and procedure the client can use. // A route is used for "one-shot" messages that don't need response such as position updates. // Produres send a response to the client. It's better to use them when client have to wait for a response from the server such as being hit. // Procedures use more bandwidth than regular routes. // // In our case, the server mostly has procedures as the client always needs to wait for a response from the server since it controls the game. _scene.AddProcedure("play", OnPlay); _scene.AddProcedure("click", OnClick); _scene.AddProcedure("update_leaderBoard", OnUpdateLeaderBoard); // this route is only used by the client to disconnect from the game (not the server) because it doesn't have to wait for the server to stop playing. _scene.AddRoute("exit", OnExit); //The starting and shutdown event are called when the scene is launched and shut down. these are useful if you need to initiate the server logic or save the game state before going down. _scene.Starting.Add(OnStarting); _scene.Shuttingdown.Add(OnShutdown); _log.Debug("server", "configuration complete"); }
public server(ISceneHost scene) { _scene = scene; _scene.GetComponent <ILogger>().Debug("server", "starting configuration"); _env = _scene.GetComponent <IEnvironment>(); _scene.Connecting.Add(onConnecting); _scene.Connected.Add(onConnected); _scene.Disconnected.Add(onDisconnected); _scene.AddRoute("enable_action", OnEnableAction); _scene.AddRoute("disable_action", OnDisableAction); _scene.AddRoute("firing_weapon", onFiringWeapon); _scene.AddRoute("chat", onReceivingMessage); _scene.Starting.Add(onStarting); _scene.Shuttingdown.Add(onShutdown); _scene.GetComponent <ILogger>().Debug("server", "configuration complete"); }
public server(ISceneHost scene) { _scene = scene; _scene.GetComponent<ILogger>().Debug("server", "starting configuration"); _env = _scene.GetComponent<IEnvironment>(); _scene.Connecting.Add(onConnecting); _scene.Connected.Add(onConnected); _scene.Disconnected.Add(onDisconnected); _scene.AddRoute("enable_action", OnEnableAction); _scene.AddRoute("disable_action", OnDisableAction); _scene.AddRoute("firing_weapon", onFiringWeapon); _scene.AddRoute("chat", onReceivingMessage); _scene.Starting.Add(onStarting); _scene.Shuttingdown.Add(onShutdown); _scene.GetComponent<ILogger>().Debug("server", "configuration complete"); }
public static TesterBehavior AddTesterBehaviorToScene(ISceneHost scene) { var result = new TesterBehavior(scene); scene.Starting.Add(result.OnStarting); scene.Connected.Add(result.OnConnected); scene.Disconnected.Add(result.OnDisconnected); scene.AddRoute("echo", result.OnEcho); scene.AddRoute("transfert", result.OnTransfert); scene.AddRoute("broadcast", result.OnBroadcast); scene.AddProcedure("rpc", result.OnRpc); scene.AddProcedure("rpcping", result.OnRpcPing); scene.Shuttingdown.Add(result.OnShutDown); return result; }
public static TesterBehavior AddTesterBehaviorToScene(ISceneHost scene) { var result = new TesterBehavior(scene); scene.Starting.Add(result.OnStarting); scene.Connected.Add(result.OnConnected); scene.Disconnected.Add(result.OnDisconnected); scene.AddRoute("echo", result.OnEcho); scene.AddRoute("transfert", result.OnTransfert); scene.AddRoute("broadcast", result.OnBroadcast); scene.AddProcedure("rpc", result.OnRpc); scene.AddProcedure("rpcping", result.OnRpcPing); scene.Shuttingdown.Add(result.OnShutDown); return(result); }
public GameScene(ISceneHost scene) { if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } _scene = scene; _scene.Connected.Add(OnConnected); _scene.Disconnected.Add(OnDisconnected); _scene.AddRoute("position.update", OnPositionUpdate); _scene.AddProcedure("getShipInfos", OnGetShipInfos); _scene.AddProcedure("ship.killCount", OnGetShipKillCount); _scene.AddProcedure("skill", UseSkill); _scene.Starting.Add(OnStarting); _scene.Shuttingdown.Add(OnShutdown); }
public RTypeMainLobby(ISceneHost scene) { m_scene = scene; m_log = m_scene.GetComponent<ILogger>(); m_env = m_scene.GetComponent<IEnvironment>(); connectClientAPI(); m_scene.Connecting.Add(onConnecting); m_scene.Connected.Add(onConnected); m_scene.Shuttingdown.Add(onShuttingDown); m_scene.Disconnected.Add(onDisconnected); m_scene.AddProcedure("GetListGames", onGetListGames); m_scene.AddProcedure("JoinGame", onJoinGame); m_scene.AddRoute("UpdateGame", onUpdateGame); m_scene.AddRoute("GetReady", onGetReady); m_scene.AddRoute("CreateGame", onCreateGame); m_scene.AddRoute("DestroyGame", onDestroyGame); m_scene.AddRoute("QuitGame", onQuitGame); }
/// <summary> /// Listen to messages on the specified route, deserialize them and execute the given handler for eah of them. (Duplicate of AddRoute for compatibility) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="scene">The scene on which the route messages will be listened.</param> /// <param name="route">The route to listen.</param> /// <param name="handler">The handler to execute for each message on the route.</param> /// <returns>An IDisposable object you can use to unregister the handler.</returns> /// <remarks>RegisterRoute is an alias to the AddRoute method.</remarks> public static IDisposable RegisterRoute <T>(this ISceneHost scene, string route, Action <T> handler) { return(scene.AddRoute(route, handler)); }
public RTypeMainGame(ISceneHost scene) { m_running = false; m_started = false; m_game = null; m_nbPlayer = 0; m_scene = scene; m_log = m_scene.GetComponent<ILogger>(); m_env = m_scene.GetComponent<IEnvironment>(); m_scene.Starting.Add(onStarting); m_scene.Shuttingdown.Add(onShutdown); m_scene.Connecting.Add(onConnecting); m_scene.Connected.Add(onConnected); m_scene.Disconnected.Add(onDisconnected); m_scene.AddRoute("PosUpdate", onPosUpdate); m_scene.AddRoute("Fire", onFire); m_scene.AddRoute("GameInfos", onGetGameInfos); m_scene.AddRoute("Collision", onGetCollision); m_scene.AddRoute("OutOfScreen", onEntityOutOfScreen); }