Esempio n. 1
0
        /// <summary>
        /// when a user disconnects, notify the servant layer
        /// </summary>
        /// <param name="AContext"></param>
        public static void OnDisconnect(UserContext AContext)
        {
            Log.Info("[CLIENT->PROXY]: Client " + AContext.ClientAddress.ToString() + " disconnected.");

            //Proxy.onlineUsers.Remove(AContext.ClientAddress.ToString());
            Proxy.sendClientDisconnectToServer(AContext); //handled by the gameserver side of the proxy
        }
Esempio n. 2
0
        /// <summary>
        ///  notify a server that a client just connected
        /// </summary>
        /// <param name="client"></param>
        public void SendClientConnect(UserContext client)
        {
            ServerContext server = PickServer();

            Message resp = new Message();
            resp.Type = ResponseType.Connection;
            resp.Data = client.ClientAddress.ToString();

            server.Send(Newtonsoft.Json.JsonConvert.SerializeObject(resp));
        }
Esempio n. 3
0
 private void OnConnected(UserContext context)
 {
     //TODO :: Logging?
     var client = new Client
     {
         Id = Guid.NewGuid(),
         Context = context
     };
     context.Data = client;
     _clients.TryAdd(client.Id, client);
 }
Esempio n. 4
0
 private void OnDisconnect(UserContext context)
 {
     //TODO :: Logging?
     if (context.Data != null)
     {
         var client = context.Data as Client;
         if (client != null)
         {
             _clients.TryRemove(client.Id, out client);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Events generated by client connections
        /// </summary>
        /// <param name="AContext"></param>
        public static void OnConnect(UserContext AContext)
        {
            Log.Info("[CLIENT->PROXY]: " + AContext.ClientAddress.ToString() + " connected.");

            User me = new User();
            me.n = AContext.ClientAddress.ToString();
            me.Context = AContext;
            AContext.TimeToProcess = DateTime.Now.Ticks;

            Proxy.onlineUsers.Add(me.n, me.Context);
            Proxy.sendClientConnectToServer(AContext);
        }
Esempio n. 6
0
 /// <summary>
 /// when proxy receives a msg in JSON format from a client, log it, convert it, and forward it to servant layer
 /// </summary>
 /// <param name="AContext"></param>
 public static void OnReceive(UserContext AContext)
 {
     //Log.Info("[CLIENT->PROXY]: Received " + AContext.DataFrame.ToString() + " from : " + AContext.ClientAddress.ToString());
     long timestamp = DateTime.Now.Ticks;
     User me = new User();
     me.n = AContext.ClientAddress.ToString();
     AContext.ReceivedPackets++;
     try
     {
         string json = AContext.DataFrame.ToString();
         Position pos = JsonConvert.DeserializeObject<Position>(json);
         me.p = pos;
         //Log.Info("[CLIENT->PROXY]: Position received from Client: " + pos.t.ToString() + ":" + pos.l.ToString() + ":" + pos.z.ToString());
     }
     catch (Exception e)
     {
         // Hack: Java client is throwing weird messages filled with '/0'. Temp fix
         string test = AContext.DataFrame.ToString();
         if (test.StartsWith("\0") == false)
             Log.Warn("[CLIENT->PROXY]: Error parsing Json into a position in ClientServer.OnReceive, JSON message was: " + AContext.DataFrame.ToString() + ". Error is: " + e.Message + e.StackTrace);
     }
     Proxy.sendSetPositionToServer(me,timestamp); // so far, the messages received only deal with user position updates
 }
Esempio n. 7
0
        private void OnReceive(UserContext context)
        {
            //TODO :: Logging?
            var client = context.Data as Client;
            if (client != null)
            {
                Request[] requests = client.GetRequests();
                if (requests != null)
                {
                    if (requests.Length > 0)
                    {
                        foreach (Request request in requests)
                        {
                            request.From = client;

                            if (TryForward(request))
                            {
                                //Only requests that are forwarded need to be tracked.
                                client.Requests.TryAdd(request.Id, request);
                            }
                            else
                            {
                                client.Error(request, Message.ServerUnavailable);
                            }
                        }
                    }
                }
                else
                {
                    client.Error(null, Message.RequestMalformed);
                }
            }
            else
            {
                context.Send(String.Empty, true); //Close
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Context"/> class.
 /// </summary>
 public Context()
 {
     Buffer = new byte[_BufferSize];
     this.UserContext = new UserContext(this);
 }
Esempio n. 9
0
        /// <summary>
        /// Sends an error message to the client who caused the error
        /// </summary>
        /// <param name="ErrorMessage">Details of the error</param>
        /// <param name="AContext">The user's connection context</param>
        private static void SendError(string ErrorMessage, UserContext AContext, ServerMessage message)
        {
            Log.Warn("Error Message: " + ErrorMessage);
            Message r = new Message();

            r = new Message();
            r.Type = ResponseType.Error;
            r.Data = new { Message = ErrorMessage };

            //AContext.Send(JsonConvert.SerializeObject(r));
        }
Esempio n. 10
0
 private void OnConnect(UserContext context)
 {
     //TODO :: Logging?
 }
Esempio n. 11
0
 private void OnSend(UserContext context)
 {
     //TODO :: Logging?
 }
Esempio n. 12
0
 public LoggingObject(long _lastupdate, UserContext _user, long _timetoprocess)
 {
     lastupdate = _lastupdate;
     timetoprocess = _timetoprocess;
     user = _user;
 }
Esempio n. 13
0
 /// <summary>
 /// when a message is sent from the proxy to one client, log it
 /// </summary>
 /// <param name="AContext"></param>
 public static void OnSend(UserContext AContext)
 {
     Log.Info("[PROXY->CLIENT]: Sent: " + UTF8Encoding.UTF8.GetString(AContext.SentData) + " to: " + AContext.ClientAddress.ToString());
 }