Example #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);
 }
Example #2
0
 /// <summary>
 /// Add a user to a chat room
 /// </summary>
 /// <param name="c">Client adding a user</param>
 /// <param name="s">Socket message with the user data and stuff</param>
 public static void AddUserToChat(Client c, SocketMessage s)
 {
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     lock (Rooms)
     {
         var rid = (long?)s["roomid"];
         if (rid == null || rid == -1)
         {
             Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
             return;
         }
         var user = (User)s["user"];
         if (user == null)
         {
             Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
             return;
         }
         ChatRoom cr = Rooms.FirstOrDefault(r => r.ID == rid);
         if (cr != null)
         {
             if (cr.AddUser(user))
             {
                 Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
                 return;
             }
         }
     }
     Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
 }
        private void EndHostGame(SocketMessage sm)
        {
            int port = (int)sm["port"];
            Program.DebugTrace.TraceEvent(System.Diagnostics.TraceEventType.Information, 0, "Connecting to port: " + port.ToString());
            Program.lobbyClient.CurrentHostedGamePort = port;
            if(port > -1)
            {
                Program.GameSettings.UseTwoSidedTable = true;
                Program.Game = new Game(GameDef.FromO8G(Game.Filename));
                Program.IsHost = true;
                IPAddress[] ad = new IPAddress[0];
            #if(DEBUG)
                ad = new IPAddress[1];
                IPAddress ip = IPAddress.Parse("127.0.0.1");
            #else
                ad = Dns.GetHostAddresses(Program.LobbySettings.Server);
                IPAddress ip = ad[0];
            #endif

                if (ad.Length > 0)
                {
                    Program.Client = new Networking.Client(ip, port);
                    Program.Client.Connect();
                    this.Dispatcher.Invoke(new Action(dothenavigate));

                }
            }
        }
Example #4
0
 /// <summary>
 /// Whenever a chat message request comes in, it goes through here
 /// and gets filtered to the appropriate room.
 /// </summary>
 /// <param name="c">Client as the sender</param>
 /// <param name="sm">Data as the data.</param>
 public static void ChatMessage(Client c,SocketMessage sm)
 {
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     lock (Rooms)
     {
         long? rid = (long?)sm["roomid"];
         string mess = (string)sm["mess"];
         if (rid == null || mess == null)
         {
             Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
             return;
         }
         if (String.IsNullOrWhiteSpace(mess))
         {
             Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
             return;
         }
         long rid2 = (long)rid;
         ChatRoom cr = Rooms.FirstOrDefault(r => r.ID == rid2);
         if (cr != null)
         {
             LazyAsync.Invoke(()=>cr.ChatMessage(c.Me, mess));
         }
         Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     }
 }
Example #5
0
 public HostedGameData(SocketMessage sm)
     : base("gameitem", "gameitem", "octgn:gameitem")
 {
     GameGuid = (Guid)sm["guid"];
     GameVersion = (Version)sm["version"];
     Port = (int)sm["port"];
     Name = (string)sm["name"];
     UserHosting = ((User)sm["hoster"]);
     GameStatus = EHostedGame.StartedHosting;
     TimeStarted = new DateTime(DateTime.Now.ToUniversalTime().Ticks);
 }
Example #6
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");
 }
Example #7
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);
 }
Example #8
0
 /// <summary>
 /// Sends a socket message to all connected clients.
 /// </summary>
 /// <param name="sm">Message to send.</param>
 public static void AllUserMessage(SocketMessage sm)
 {
     lock (ClientLocker)
     {
         #if(TestServer)
             Trace.WriteLine("#WriteAll: " + sm.Header);
         #endif
         foreach (Client c in Clients)
         {
             Client cl2 = c;
             if (cl2.LoggedIn)
             {
                 #if(TestServer)
                     Trace.WriteLine("#TryWriteTo[" + cl2.Id + "](" + sm.Header + ")");
                 #endif
                 LazyAsync.Invoke(() => cl2.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;
 }
Example #10
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();
 }
Example #11
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);
 }
Example #12
0
 public static void WriteMessageToClient(SocketMessage sm,int uid)
 {
     lock (ClientLocker)
     {
         Client cl = Clients.FirstOrDefault(c => c.LoggedIn && c.Me.Uid == uid);
         if (cl != null)
         {
             LazyAsync.Invoke(()=>cl.WriteMessage(sm));
         }
     }
 }
Example #13
0
 public static void WriteMessageToClient(SocketMessage sm,string email)
 {
     lock (ClientLocker)
     {
         Client cl = Clients.FirstOrDefault(c => c.LoggedIn && c.Me.Email.ToLower() == email.ToLower());
         if (cl != null)
             LazyAsync.Invoke(()=>cl.WriteMessage(sm));
     }
 }
Example #14
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);
 }
Example #15
0
 public void WriteMessage(SocketMessage message)
 {
     lock (SocketLocker)
     {
         if (IsDisposed)
             return;
         byte[] data = SocketMessage.Serialize(message);
         byte[] messagesize = BitConverter.GetBytes(data.LongLength);
         try
         {
             Sock.Client.Send(messagesize);
             Sock.Client.Send(data);
             //Sock.GetStream().Flush();
         }
         catch (SocketException se)
         {
             if (se.ErrorCode == 10058)
                 return;
             LazyAsync.Invoke(() => Stop());
         }
         catch (ObjectDisposedException)
         {
             LazyAsync.Invoke(() => Stop());
         }
         catch (NullReferenceException)
         {
         }
         catch (Exception e)
         {
             Debug.WriteLine(e);
             if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();
         }
     }
 }
Example #16
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);
 }
Example #17
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);
 }
Example #18
0
 /// <summary>
 /// Join a chat room.
 /// </summary>
 /// <param name="c">Client that wants to join</param>
 /// <param name="s">Socket message stuffed with data.</param>
 public static void JoinChatRoom(Client c, SocketMessage s)
 {
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     lock (Rooms)
     {
         Logger.L(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
         var rid = (long?)s["roomid"];
         if (rid == null)
             return;
         if (rid == -1)
             MakeRoom(c);
         else
         {
             ChatRoom cr = Rooms.FirstOrDefault(r => r.ID == rid);
             if (cr != null)
                 cr.AddUser(c.Me);
             else
                 MakeRoom(c);
         }
         Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     }
 }
Example #19
0
 public void WriteMessage(SocketMessage sm)
 {
     Socket.WriteMessage(sm);
 }
Example #20
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;
 }
Example #21
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);
 }
Example #22
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);
 }
Example #23
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);
 }
Example #24
0
 public object Clone()
 {
     var sm = new SocketMessage(Header.Clone() as String) {Data = Data.Clone() as NameValuePair[]};
     return sm;
 }
Example #25
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);
 }
Example #26
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);
     }
 }
Example #27
0
 public static byte[] Serialize(SocketMessage message)
 {
     using (var ms = new MemoryStream())
     {
         try
         {
             var bf = new BinaryFormatter();
             bf.Serialize(ms, message);
             ms.Flush();
             return ms.ToArray();
         }
         catch (Exception e)
         {
             Trace.TraceError("sm1:" + e.Message, e);
         }
     }
     return null;
 }
Example #28
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();
     }
 }
Example #29
0
 public static void AllUserMessageUidList(int[] uids, SocketMessage sm)
 {
     lock (ClientLocker)
     {
         foreach (Client c in Clients)
         {
             Client cl2 = c;
             if (cl2.LoggedIn && uids.Contains(cl2.Me.Uid))
             {
                 LazyAsync.Invoke(() => cl2.WriteMessage(sm));
             }
         }
     }
 }
Example #30
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);
 }