Beispiel #1
0
 /// <summary>
 /// Add a user to a chat room
 /// </summary>
 /// <param name="u"></param>
 /// <param name="chatid"></param>
 public void AddUserToChat(User u, long chatid)
 {
     SocketMessage sm = new SocketMessage("addusertochat");
     sm.AddData("roomid", chatid);
     sm.AddData("user", u);
     Parent.WriteMessage(sm);
 }
 public void Decline()
 {
     SocketMessage sm = new SocketMessage("acceptfriend");
     sm.AddData("uid", User.Uid);
     sm.AddData("accept", false);
     LobbyClient.WriteMessage(sm);
     Notification[] ns = LobbyClient.GetNotificationList();
     for (int i = 0; i < ns.Length; i++)
     {
         FriendRequestNotification fr = ns[i] as FriendRequestNotification;
         if (fr != null)
         {
             if (fr.User.Uid == User.Uid)
             {
                 LobbyClient.RemoveNotification(ns[i]);
                 break;
             }
         }
     }
     Dismissed = true;
 }
Beispiel #3
0
 public static void KillServerInTime(int minutes)
 {
     if (minutes == 0)
     {
         //_sentMinuteWarning = false;
         //_killTime = new DateTime(0);
         return;
     }
     //_killTime = DateTime.Now.AddMinutes(minutes);
     var sm = new SocketMessage("servermessage");
     sm.AddData("message",
                "Server will be shutting down in " + minutes.ToString(CultureInfo.InvariantCulture) + " minutes");
 }
Beispiel #4
0
 public static void KillServerInTime(int minutes)
 {
     if(minutes == 0)
     {
         _sentMinuteWarning = false;
         _killTime = new DateTime(0);
         return;
     }
     _killTime = DateTime.Now.AddMinutes((int)minutes);
     SocketMessage sm = new SocketMessage("servermessage");
     sm.AddData("message", "Server will be shutting down in " + minutes.ToString() + " minutes");
     Server.AllUserMessage(sm);
 }
Beispiel #5
0
 private static void CheckKillTime(Object stateInfo)
 {
     if (_killTime == null)
         return;
     if (_killTime == new DateTime(0))
         return;
     if (_killTime.Ticks > DateTime.Now.Ticks)
     {
         if(new TimeSpan(_killTime.Ticks - DateTime.Now.Ticks).TotalMinutes <= 1)
         {
             if(!_sentMinuteWarning)
             {
                 SocketMessage sm = new SocketMessage("servermessage");
                 sm.AddData("message","Server will be shutting down in about a minute.");
                 Server.AllUserMessage(sm);
                 _sentMinuteWarning = true;
             }
         }
         return;
     }
     Quit();
 }
Beispiel #6
0
 /// <summary>
 /// Send a chat message to a room.
 /// </summary>
 /// <param name="rid"></param>
 /// <param name="message"></param>
 public void SendChatMessage(long rid,string message)
 {
     SocketMessage sm = new SocketMessage("chatmessage");
         sm.AddData("roomid", rid);
         sm.AddData("mess", message);
         Parent.WriteMessage(sm);
 }
Beispiel #7
0
 /// <summary>
 /// Leave a chat room.
 /// </summary>
 /// <param name="rid"></param>
 public void LeaveChatRoom(long rid)
 {
     SocketMessage sm = new SocketMessage("leavechat");
         sm.AddData("roomid",rid);
         Parent.WriteMessage(sm);
         Rooms.RemoveAll(r => r.ID == rid);
 }
Beispiel #8
0
 /// <summary>
 /// Join a chat room based on an RID
 /// </summary>
 /// <param name="id"></param>
 public void JoinChatRoom(long id)
 {
     SocketMessage sm = new SocketMessage("joinchatroom");
     sm.AddData("roomid", id);
     Parent.WriteMessage(sm);
 }
Beispiel #9
0
 /// <summary>
 /// This starts up a two person chat.
 /// </summary>
 /// <param name="c">Client starting the room</param>
 /// <param name="s">Socket message full of data</param>
 public static void TwoPersonChat(Client c, SocketMessage s)
 {
     var user = (User)s["user"];
     if (user == null)
         return;
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     long id = -1;
     lock(Rooms)
     {
         foreach (ChatRoom cr in Rooms)
         {
             User[] ul = cr.GetUserList();
             if (ul.Contains(user) && ul.Contains(c.Me) && ul.Length == 2)
             {
                 Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
                 return;
             }
         }
         id = MakeRoom(c);
     }
     Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     s.AddData("roomid", id);
     AddUserToChat(c, s);
 }
Beispiel #10
0
 /// <summary>
 /// Sets the users display name
 /// </summary>
 /// <param name="name"></param>
 public void SetDisplayName(string name)
 {
     SocketMessage sm = new SocketMessage("displayname");
     sm.AddData("name", name);
     WriteMessage(sm);
 }
Beispiel #11
0
 /// <summary>
 /// Sets the users custom status.
 /// </summary>
 /// <param name="CustomStatus"></param>
 public void SetCustomStatus(string CustomStatus)
 {
     SocketMessage sm = new SocketMessage("customstatus");
     sm.AddData("customstatus", CustomStatus);
     WriteMessage(sm);
 }
Beispiel #12
0
 /// <summary>
 /// Login here
 /// </summary>
 /// <param name="onFinish">Delegate for when Login is done.</param>
 /// <param name="email">Users e-mail address</param>
 /// <param name="password">Password</param>
 /// <param name="captcha">Captcha string if required</param>
 /// <param name="status">Status to log in as</param>
 public void Login(LoginFinished onFinish, LoginProgressUpdate onUpdate, string email, string password, string captcha, UserStatus status)
 {
     if(Socket.Connected)
     {
         Thread t = new Thread(() =>
                                   {
                                       //TODO Need to add a method to handle 2-step signin.
                                       _onLoginFinished = onFinish;
                                       String appName = "skylabs-LobbyClient-" + Version;
                                       Service s = new Service("code", appName);
                                       s.setUserCredentials(email, password);
                                       if(captcha != null && _mCaptchaToken != null)
                                       {
                                           onUpdate.Invoke("Verifying captcha");
                                           if(!String.IsNullOrWhiteSpace(captcha) || !String.IsNullOrWhiteSpace(_mCaptchaToken))
                                           {
                                               s.Credentials.CaptchaToken = _mCaptchaToken;
                                               s.Credentials.CaptchaAnswer = captcha;
                                           }
                                       }
                                       try
                                       {
                                           Debug.WriteLine("Querying Google...");
                                           onUpdate.Invoke("Logging into Google...");
                                           string ret = s.QueryClientLoginToken();
                                           onUpdate.Invoke("Sending login token to Server...");
                                           Debug.WriteLine("Received login token.");
                                           SocketMessage sm = new SocketMessage("login");
                                           sm.AddData("email", email);
                                           sm.AddData("token", ret);
                                           sm.AddData("status", status);
                                           WriteMessage(sm);
                                           onUpdate.Invoke("Waiting for server response...");
                                       }
                                       catch(CaptchaRequiredException ce)
                                       {
                                           _mCaptchaToken = ce.Token;
                                           if(OnCaptchaRequired != null) OnCaptchaRequired.Invoke("https://www.google.com/accounts/DisplayUnlockCaptcha", ce.Url);
                                       }
                                       catch(AuthenticationException re)
                                       {
                                           string cu = (string)re.Data["CaptchaUrl"];
                                           onFinish.Invoke(LoginResult.Failure, DateTime.Now, re.Message);
                                       }
                                       catch(WebException)
                                       {
                                           onFinish.Invoke(LoginResult.Failure, DateTime.Now, "Connection problem.");
                                       }
                                       onFinish.Invoke(LoginResult.WaitingForResponse, DateTime.Now, "");
                                   });
         t.Start();
     }
 }
Beispiel #13
0
 /// <summary>
 /// This gets called when the hoster of the game clicks 'Start game'
 /// </summary>
 public void HostedGameStarted()
 {
     if (CurrentHostedGamePort != -1)
     {
         SocketMessage sm = new SocketMessage("gamestarted");
         sm.AddData("port", CurrentHostedGamePort);
         WriteMessage(sm);
     }
 }
Beispiel #14
0
 /// <summary>
 /// Start hosting a game.
 /// </summary>
 /// <param name="callback">Callback for when the server talks back</param>
 /// <param name="game">Game</param>
 /// <param name="gamename">Name of the game</param>
 /// <param name="password">Password</param>
 public void BeginHostGame(SocketMessageResult callback, Octgn.Data.Game game, string gamename, string password)
 {
     Callbacks.Clear();
     Callbacks.Add("hostgameresponse",callback);
     SocketMessage sm = new SocketMessage("hostgame");
     sm.AddData("game",game.Id);
     sm.AddData("version",game.Version);
     sm.AddData("name",gamename);
     sm.AddData("pass",password);
     WriteMessage(sm);
 }
Beispiel #15
0
 /// <summary>
 /// Send a friend request to an e-mail
 /// </summary>
 /// <param name="email">E-mail of the friend</param>
 public void AddFriend(string email)
 {
     SocketMessage sm = new SocketMessage("addfriend");
     sm.AddData("email", email);
     WriteMessage(sm);
 }
Beispiel #16
0
 /// <summary>
 /// Create a chat room with another user.
 /// </summary>
 /// <param name="otherUser"></param>
 public void CreateChatRoom(User otherUser)
 {
     SocketMessage sm = new SocketMessage("twopersonchat");
     sm.AddData("user", otherUser);
     Parent.WriteMessage(sm);
 }
Beispiel #17
0
 /// <summary>
 /// Sets the users status. Don't ever set to Offline, use Invisible instead.
 /// </summary>
 /// <param name="s">Users status</param>
 public void SetStatus(UserStatus s)
 {
     SocketMessage sm = new SocketMessage("status");
     sm.AddData("status", s);
     WriteMessage(sm);
     Me.Status = s;
 }
Beispiel #18
0
 private static void HostedGameExited(object sender,EventArgs e)
 {
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "GamingLocker");
     lock (GamingLocker)
     {
         Logger.L(System.Reflection.MethodInfo.GetCurrentMethod().Name, "GamingLocker");
         HostedGame s = sender as HostedGame;
         if (s != null)
         {
             s.Status = Lobby.HostedGame.eHostedGame.StoppedHosting;
             SocketMessage sm = new SocketMessage("gameend");
             sm.AddData("port", s.Port);
             Action t = new Action(()=>Server.AllUserMessage(sm));
             t.BeginInvoke(null, null);
             Games.Remove(s.Port);
         }
         Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "GamingLocker");
     }
 }