public void UserCreate() { var user1 = new CoflnetUser(); var user2 = new CoflnetUser(new EntityId()); Assert.IsNotNull(user1); Assert.IsNotNull(user2); }
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 ResourceSave() { var resolver = CompositeResolver.Create(PrimitiveObjectResolver.Instance, StandardResolver.Instance); var user = new CoflnetUser(); user.AssignId(); user.OnlyFriendsMessage = true; user.FirstName = "Bernd das Brot ist"; DataController.Instance.SaveData($"res/{user.Id.ToString()}aaaa", MessagePackSerializer.Typeless.Serialize(user)); EntityManager.Instance.Save(user.Id, true); }
public void ResourceSaveAndLoad() { //CompositeResolver.RegisterAndSetAsDefault(PrimitiveObjectResolver.Instance, StandardResolver.Instance); var user = new CoflnetUser(); user.AssignId(); user.OnlyFriendsMessage = true; user.FirstName = "Bernd das Brot"; DataController.Instance.SaveData($"res/{user.Id.ToString()}aaaa", MessagePack.MessagePackSerializer.Typeless.Serialize(user)); EntityManager.Instance.Save(user.Id, true); var loadedUser = EntityManager.Instance.GetEntity <CoflnetUser> (user.Id); Assert.AreEqual(user.FirstName, loadedUser.FirstName); }
/// <summary> /// Generates a list of public userinfos out of the friend list of the current user /// </summary> /// <returns>The list.</returns> public List <PublicUserInfo> FriendList() { CoflnetUser currentUser = UserService.Instance.CurrentUser; return(currentUser.Friends.ConvertAll((Reference <CoflnetUser> input) => { PublicUserInfo userInfo; EntityManager.Instance.TryGetEntity <PublicUserInfo>(input.EntityId, out userInfo); if (userInfo == null) { userInfo = new PublicUserInfo() { Id = input.EntityId, userName = "******" }; } return userInfo; })); }
public void AddUser(CoflnetUser user) { EntityManager.Instance.CreateReference(user); }
/// <summary> /// Tries the get user. Will return false and null as the user if not found. /// </summary> /// <returns><c>true</c>, if get user was found, <c>false</c> otherwise.</returns> /// <param name="user">User.</param> public bool TryGetUser(out CoflnetUser user) { var userId = ConfigController.UserSettings.userId; return(EntityManager.Instance.TryGetEntity <CoflnetUser>(userId, out user)); }
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(); }