Example #1
0
 /// <summary>
 /// Broadcasts a position message to all online users
 /// </summary>
 /// <param name="Message">The chat message to be broadcasted</param>
 /// <param name="AContext">The user's connection context</param>
 private static void SetPosition(RCATContext RContext, ServerMessage message)
 {
     try
     {
         User user = new User();
         user = (User)serializer.Deserialize(new JTokenReader(message.Data), typeof(User));
         dataConnector.SetPosition(user.n, user.p, message.TimeStamp);
         string[] clients = dataConnector.GetAllUsersNames();
         dynamic data = new { n = user.n, p = user.p };
         RContext.Broadcast(data, clients, ResponseType.Position, message.TimeStamp);
     }
     catch (Exception e)
     {
         Log.Error(e);
     }
 }
Example #2
0
        // NOTE: This is not safe code. You may end up broadcasting to people who
        // disconnected. Luckily for us, Alchemy handles exceptions in its event methods, so we don't
        // have random, catastrophic changes.
        /// <summary>
        /// Event triggered when a user disconnected from a proxy
        /// Remove a user from the online users list 
        /// and broadcast the disconnection message to all connected users.
        /// </summary>
        /// <param name="AContext">The user's connection context</param>
        public static void OnDisconnect(RCATContext RContext, ServerMessage message)
        {
            try
            {
                Log.Info("[PROXY->SERVANT]: User disconnected: " + message.Data);

                User user = dataConnector.GetUser(message.Data);

                Message r = new Message();

                if (!String.IsNullOrEmpty(user.n))
                {
                    dataConnector.RemoveUser(user.n);
                    string[] clients = dataConnector.GetAllUsersNames();
                    RContext.Broadcast(new { n = user.n }, clients, ResponseType.Disconnect, message.TimeStamp);
                }
                else
                    Log.Warn("[PROXY->SERVANT]: User " + user.n + " not found OnDisconnect.");
            }
            catch (Exception e)
            {
                Log.Error("[PROXY->SERVANT]: Error in OnDisconnect.",e);
            }
        }