public IEnumerator CommandResponseTest() { // tell the server his id ConfigController.ApplicationSettings.id = new SourceReference(1, 1, 1, 0); ServerCore.Init(); CommandData response = null; ClientSocket.Instance.Reconnect(); ClientSocket.Instance.AddCallback(data => { response = data; }); ConfigController.ActiveUserId = SourceReference.Default; // register server command ServerCore.Commands.RegisterCommand <ServerTestCommandGet> (); yield return(new UnityEngine.WaitForSeconds(1)); // send the command ClientSocket.Instance.SendCommand( new CommandData(ConfigController.ApplicationSettings.id, -1, "", "serverTestCommandGet")); // await response yield return(new UnityEngine.WaitForSeconds(1)); // test the expected error slug Assert.AreEqual(response.GetAs <int> (), 4); ServerCore.Stop(); }
public IEnumerator CreateUserTest() { // tell the server his id ConfigController.ApplicationSettings.id = new SourceReference(1, 1, 1, 0); ServerCore.Init(); ClientSocket.Instance.Reconnect(); CommandData response = null; ClientSocket.Instance.AddCallback(data => { response = data; }); yield return(new UnityEngine.WaitForSeconds(1)); // set data var request = new RegisterUserRequest(); request.captchaToken = ""; request.clientId = ConfigController.ApplicationSettings.id; // send the command ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <RegisterUser, RegisterUserRequest> (ConfigController.ApplicationSettings.id, request)); // await response yield return(new UnityEngine.WaitForSeconds(0.5f)); Logger.Log(response.GetAs <RegisterUserResponse> ().id); // user was created in the last second Assert.IsTrue(response.GetAs <RegisterUserResponse> ().id.ResourceId > ThreadSaveIdGenerator.NextId - 10000000); ServerCore.Stop(); }
public IEnumerator ErrorResponseTest() { // Tell the server its id (so he doesn't try to pass the message on) ConfigController.ApplicationSettings.id = new SourceReference(1, 1, 1, 0); ServerCore.Init(); string returnValue = null; ClientSocket.Instance.OnError += (CoflnetException coflnetException) => { returnValue = coflnetException.Slug; }; ClientSocket.Instance.Reconnect(); yield return(new UnityEngine.WaitForSeconds(1)); var newId = new SourceReference(1, 1, 1, ThreadSaveIdGenerator.NextId); // the error is whitelisted // beause the console is also the server console this would cause the test to faild otherwise LogAssert.Expect(UnityEngine.LogType.Error, new Regex($".*{Regex.Escape(newId.ToString())}.*wasn't found on this server.*")); ClientSocket.Instance.SendCommand(new CommandData(newId), false); yield return(new UnityEngine.WaitForSeconds(1)); // test the expected error slug Assert.AreEqual(returnValue, "object_not_found"); ServerCore.Stop(); //retrivedRes.GetCommandController().ExecuteCommand(new CommandData(id, null, "coreTest")); }
private static void Main(string[] args) { ServerCore.Init(6, args); ServerChat.Init(); ServerCore.Start(new ChatMessageManager()); Console.Title = string.Format("{0} - {1}", ServerUtil.GetServerName(ServerCore.Type), ServerCore.Id); }
public IEnumerator MessageTransitPersitenceCrossServerTest() { // tell the server his id ConfigController.ApplicationSettings.id = new SourceReference(1, 1, 1, 0); ServerCore.Init(); ClientSocket.Instance.Reconnect(); CommandData response = null; ClientSocket.Instance.AddCallback(data => { response = data; }); ConfigController.ActiveUserId = SourceReference.Default; yield return(new UnityEngine.WaitForSeconds(0.5f)); // set data var request = new RegisterUserRequest(); request.captchaToken = ""; request.clientId = ConfigController.ApplicationSettings.id; // send the command ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <RegisterUser, RegisterUserRequest> (ConfigController.ApplicationSettings.id, request)); // await response yield return(new UnityEngine.WaitForSeconds(0.5f)); var login = response.GetAs <RegisterUserResponse> (); ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <Coflnet.LoginUser, LoginParams> ( ConfigController.ApplicationSettings.id, new LoginParams() { id = login.id, secret = login.secret })); yield return(new WaitForSeconds(0.5f)); // register second user on virtual other server var receiverUser = CoflnetUser.Generate(new SourceReference(1, 1, 2, 0)); receiverUser.Id = new SourceReference(3, 1, 2, ThreadSaveIdGenerator.NextId); receiverUser.GetCommandController().OverwriteCommand <ChatMessageCommand> (); Logger.Log(receiverUser.Id); (new CoflnetUser()).GetCommandController().OverwriteCommand <TestCommandWithPermission> (); ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <ChatMessageCommand, string> (receiverUser.Id, "hi")); yield return(new WaitForSeconds(0.5f)); // message is saved Assert.IsTrue(MessagePersistence.ServerInstance.GetMessagesFor(receiverUser.Id).ToList().Any()); }
public void CommandExtention() { // loads the extention ServerCore.Init(); var loginUser = ServerCore.Commands.GetCommand("loginUser"); Assert.IsNotNull(loginUser); ServerCore.Stop(); }
public IEnumerator CreateAndLoginUserTest() { // tell the server his id ConfigController.ApplicationSettings.id = new SourceReference(1, 1, 1, 0); ServerCore.Init(); CommandData response = null; ClientSocket.Instance.AddCallback(data => { response = data; }); yield return(new UnityEngine.WaitForSeconds(1)); // set data var request = new RegisterUserRequest(); request.captchaToken = ""; request.clientId = ConfigController.ApplicationSettings.id; // send the command ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <RegisterUser, RegisterUserRequest> (ConfigController.ApplicationSettings.id, request)); // await response yield return(new UnityEngine.WaitForSeconds(0.5f)); var login = response.GetAs <RegisterUserResponse> (); ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <Coflnet.LoginUser, LoginParams> (ConfigController.ApplicationSettings.id, new LoginParams() { id = login.id, secret = login.secret })); // tell the client that we are logged in ConfigController.ActiveUserId = login.id; yield return(new WaitForSeconds(0.5f)); // register test command on user (new CoflnetUser()).GetCommandController().OverwriteCommand <TestCommandWithPermission> (); ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <TestCommandWithPermission, int> (login.id, 1), true); yield return(new WaitForSeconds(0.5f)); // user was created in the last second Assert.IsTrue(response.GetAs <int> () == 5); }
public static void Main(string[] args) { ServerCore.Init(0, args); ServerAdmin.Init(); ServerCore.Start(new AdminMessageManager()); if (EnvironmentSettings.Environment.Equals("prod", StringComparison.InvariantCultureIgnoreCase)) { ServerStatus.SetStatus(ServerStatusType.MAINTENANCE, 0, 0); } Program.CreateWebHostBuilder(args).Build().Run(); }
/// <summary> /// Initialized the global <see cref="CoflnetCore.Instance"/> as a `devCore`. /// Will reset the development enviroment when called again (to support multiple unit tests) /// </summary> /// <param name="id">Application/Server Id to use</param> /// <param name="preventDefaultScreens"><c>true</c> when default settings (dummys) should NOT be set such as <see cref="DummyPrivacyScreen"/></param> /// <param name="preventInit"><c>true</c> when The Inits of Client and Server-Cores should not be invoked and client should be prepared like a fresh install</param> public static void Init(EntityId id, bool preventDefaultScreens = false, bool preventInit = false) { //[Deprecated] ConfigController.ActiveUserId = id; // sets the primary managing server ConfigController.ApplicationSettings.id = id.FullServerId; if (!preventDefaultScreens) { SetupDefaults(); } // to have instances loaded var toLoadInstance = ClientCore.ClientInstance; var serverInstance = ServerCore.ServerInstance; if (DevInstance == null) { DevInstance = new DevCore(); DevInstance.simulationInstances = new Dictionary <EntityId, SimulationInstance> (); CoflnetCore.Instance = DevInstance; } else { // reset if there was an devinstance bevore DevInstance.simulationInstances.Clear(); ServerCore.ServerInstance = new ServerCoreProxy(); ClientCore.ClientInstance = new ClientCoreProxy(); } DevInstance.AddServerCore(id.FullServerId); if (!id.IsServer) { DevInstance.AddClientCore(id); } else { DevInstance.AddClientCore(EntityId.Default); } if (!preventInit) { ServerCore.Init(); ClientCore.Init(); } }
public IEnumerator ConnectingTest() { ServerCore.Init(); ClientSocket.Instance.AddCallback(data => { }); // p ClientSocket.Instance.Reconnect(); yield return(new UnityEngine.WaitForSeconds(0.5f)); LogAssert.Expect(UnityEngine.LogType.Error, new Regex($".*There is no server with the id 0.*")); ClientSocket.Instance.SendCommand(new CommandData()); //retrivedRes.GetCommandController().ExecuteCommand(new CommandData(id, null, "coreTest")); yield return(new UnityEngine.WaitForSeconds(0.5f)); ServerCore.Stop(); //Assert.IsTrue(res.value == 5); }
public IEnumerator DistributionTest() { ConfigController.ApplicationSettings.id = new SourceReference(1, 1, 1, 0); ServerCore.Init(); string returnValue = null; ClientSocket.Instance.OnError += (CoflnetException coflnetException) => { returnValue = coflnetException.Slug; }; var secondClient = ClientSocket.NewInstance(); //secondClient.SendCommand(CommandData.CreateCommandData<Login>); ClientSocket.Instance.Reconnect(); yield return(new UnityEngine.WaitForSeconds(1)); var newId = new SourceReference(1, 1, 1, ThreadSaveIdGenerator.NextId); // Ignore log message LogAssert.ignoreFailingMessages = true; ClientSocket.Instance.SendCommand(new CommandData(newId), false); yield return(new UnityEngine.WaitForSeconds(1)); // test the expected error slug Assert.AreEqual(returnValue, "object_not_found"); // Reset ServerCore.Stop(); LogAssert.ignoreFailingMessages = false; }
static void Main(string[] args) { Console.WriteLine("Hello World!"); FileController.dataPaht += "/wow"; Console.WriteLine(FileController.dataPaht); var server = CoflnetSocket.socketServer; server.AddWebSocketService <WoWProxy>("/wow", () => { var s = new WoWProxy(); return(s); }); ServerCore.Init(new SourceReference(1, 0)); Console.WriteLine("just sleeping a bit"); for (long i = 0; i < long.MaxValue; i++) { Console.Write("a"); Thread.Sleep(1000); } }
public void ServerCoreInit() { ServerCore.Init(); }
public IEnumerator MessageTransitPersitenceTest() { // tell the server his id ConfigController.ApplicationSettings.id = new SourceReference(1, 1, 1, 0); ServerCore.Init(); CommandData response = null; ClientSocket.Instance.Reconnect(); ClientSocket.Instance.AddCallback(data => { response = data; }); ConfigController.ActiveUserId = SourceReference.Default; yield return(new UnityEngine.WaitForSeconds(0.5f)); // set data var request = new RegisterUserRequest(); request.captchaToken = ""; request.clientId = ConfigController.ApplicationSettings.id; // send the command ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <RegisterUser, RegisterUserRequest> (ConfigController.ApplicationSettings.id, request)); // await response yield return(new UnityEngine.WaitForSeconds(0.5f)); var login = response.GetAs <RegisterUserResponse> (); ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <Coflnet.LoginUser, LoginParams> ( ConfigController.ApplicationSettings.id, new LoginParams() { id = login.id, secret = login.secret })); yield return(new WaitForSeconds(0.5f)); // register second user var receiverUser = CoflnetUser.Generate(ConfigController.ApplicationSettings.id); receiverUser.GetCommandController().OverwriteCommand <ChatMessageCommand> (); //register the command (new CoflnetUser()).GetCommandController().OverwriteCommand <TestCommandWithPermission> (); //tell the client what user we are ConfigController.ActiveUserId = login.id; ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <ChatMessageCommand, string> (receiverUser.Id, "hi")); yield return(new WaitForSeconds(0.5f)); // message is saved Assert.IsTrue(MessagePersistence.ServerInstance.GetMessagesFor(receiverUser.Id).ToList().Any()); // connect with the receiver ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <Coflnet.LoginUser, LoginParams> ( ConfigController.ApplicationSettings.id, new LoginParams() { id = receiverUser.Id, secret = receiverUser.Secret })); yield return(new WaitForSeconds(0.5f)); // tell the Client socket the identity ConfigController.ActiveUserId = receiverUser.Id; ClientSocket.Instance.SendCommand( CommandData.CreateCommandData <Coflnet.ReceiveableResource.GetMessages, int> (receiverUser.Id, 0)); yield return(new WaitForSeconds(0.5f)); Logger.Log(response.type); // message is delivered Assert.AreEqual(response.GetAs <string> (), "hi"); // message is deleted Assert.IsFalse(MessagePersistence.ServerInstance.GetMessagesFor(receiverUser.Id).ToList().Any()); // clean up ServerCore.Stop(); }