Inheritance: MonoBehaviour
        public ServerConnectedPlayers(ServerMessaging serverMessaging, MonoBehaviour mono, string name) : base(name)
        {
            _serverMessaging = serverMessaging;

            mono.StartCoroutine(ManageTimeout());

            _serverMessaging.RegisterMessaging((short) NetworkMessages.UpdatePlayerOnServer, UpdatePlayerServer);
        }
 private Dictionary <string, object> ReleaseItem(int quantity, string productName)
 {
     if (_stock.ContainsKey(productName))
     {
         _stock[productName].Quantity += quantity;
         return(new Dictionary <string, object> {
             { "nReleased", quantity }
         });
     }
     return(ServerMessaging.BuildErrorResponse("Item doesn't exist !"));
 }
        public override void OnStartServer()
        {
            base.OnStartServer();

            _serverMessaging = new ServerMessaging(this);
            Players          = new ServerConnectedPlayers(_serverMessaging, this, _userName);

            OnServerStarted?.Invoke();

            Debug.Log("Server Started");
        }
        private void Send()
        {
            while (this.m_started)
            {
                this.m_sendResetEvent.WaitOne();

                while (this.m_sendQueue.TryDequeue(out QueueItem item))
                {
                    item.Socket.Send(ServerMessaging.WriteMessage(item.Message));
                }
            }
        }
        public static void Start(ServerMessageManager messageManager)
        {
            Logging.SEND_LOGS = true;
            ServerMessaging.Init(messageManager);
            ServerListenSocket.Init();

            if (ServerManager.GetServerCount(0) != 0 && ServerCore.Type != 0)
            {
                ServerStatus.SetStatus(ServerStatusType.MAINTENANCE, 0, 0);
                ServerMessageManager.SendMessage(new AskForServerStatusMessage(), ServerManager.GetSocket(0, 0));
            }
        }
Exemple #6
0
        public void Error(string message)
        {
            Debug.WriteLine("[LOGIC] " + message);

            if (Logging.SEND_LOGS && ServerManager.IsInit() && ServerManager.GetServerCount(0) != 0)
            {
                ServerMessaging.Send(new GameLogMessage
                {
                    LogType = 1,
                    Message = message
                }, ServerManager.GetSocket(0, 0));
            }
        }
        public static ServerRequestArgs Create(ServerRequestMessage message, ServerSocket socket, int timeout = 30)
        {
            ServerRequestArgs request = new ServerRequestArgs(timeout);
            long requestId            = Interlocked.Increment(ref ServerRequestManager.m_counters);

            message.RequestId = requestId;

            if (!ServerRequestManager.m_requests.TryAdd(requestId, request))
            {
                throw new Exception("Unable to add new message");
            }
            ServerMessaging.Send(message, socket);

            return(request);
        }
Exemple #8
0
        public static void Error(string message)
        {
            Debug.WriteLine("[ERROR] " + message);

            if (Logging.SEND_LOGS && ServerManager.IsInit() && ServerManager.GetServerCount(0) != 0)
            {
                ServerMessaging.Send(new ServerLogMessage
                {
                    LogType = 1,
                    Message = message
                }, ServerManager.GetSocket(0, 0));
            }

            File.AppendAllText("logs.txt", message + "\n");
        }
 private Dictionary <string, object> ReserveItem(int quantity, string productName)
 {
     if (_stock.ContainsKey(productName))
     {
         var item = _stock[productName];
         if (quantity <= item.Quantity)
         {
             item.Quantity -= quantity;
             return(new Dictionary <string, object> {
                 { "nReserved", quantity }
             });
         }
         return(ServerMessaging.BuildErrorResponse("Not enough quantity in stock !"));
     }
     return(ServerMessaging.BuildErrorResponse("Item doesn't exist !"));
 }
        StockManager()
        {
            LoadStock();
            var serverRabbitMQ = new ServerMessaging("localhost", "stock_queue");

            serverRabbitMQ.Listen((ea, json) => {
                if (json == null)
                {
                    serverRabbitMQ.Send(ea, ServerMessaging.BuildErrorResponse("Bad request formatting."));
                }
                try
                {
                    Dictionary <string, object> response;
                    string action = (string)json["action"];
                    if (action == "list")
                    {
                        response = ListItems();
                    }
                    else
                    {
                        string productName = (string)json["product"];
                        int quantity       = (int)(long)json["quantity"];
                        if (action == "reserve")
                        {
                            response = ReserveItem(quantity, productName);
                        }
                        else if (action == "release")
                        {
                            response = ReleaseItem(quantity, productName);
                        }
                        else
                        {
                            throw new Exception("Unhandled action.");
                        }
                    }
                    serverRabbitMQ.Send(ea, response);
                }
                catch (Exception e)
                {
                    serverRabbitMQ.Send(ea, ServerMessaging.BuildErrorResponse(e.Message));
                }
            });
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
            serverRabbitMQ.Close();
        }
        private void OnReceive(byte[] buffer)
        {
            if (buffer.Length > 0)
            {
                ServerMessage message = ServerMessaging.ReadMessage(buffer, buffer.Length);

                if (message != null)
                {
                    this.ReceiveMessage(message);
                }
            }
            else
            {
                this.m_pingWatch.Stop();
                this.m_ping = (int)this.m_pingWatch.ElapsedMilliseconds;
                this.OnPingTestCompleted();
            }
        }
Exemple #12
0
        UserManager()
        {
            LoadUser();
            var serverRabbitMQ = new ServerMessaging("localhost", "user_queue");

            serverRabbitMQ.Listen((ea, json) => {
                if (json == null)
                {
                    serverRabbitMQ.Send(ea, BuildErrorResponse("Bad request formatting."));
                }
                try
                {
                    string username = (string)json["Username"];
                    Dictionary <string, object> response;
                    if (_user.ContainsKey(username))
                    {
                        var user = _user[username];
                        response = new Dictionary <string, object> {
                            { "user", JsonConvert.SerializeObject(user) }
                        };
                    }
                    else
                    {
                        response = BuildErrorResponse("Cannot find user.");
                    }

                    serverRabbitMQ.Send(ea, response);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    serverRabbitMQ.Send(ea, BuildErrorResponse(e.Message));
                }
            });
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
            serverRabbitMQ.Close();
        }
        BillManager()
        {
            var serverRabbitMQ = new ServerMessaging("localhost", "bill_queue");

            serverRabbitMQ.Listen((ea, requestBody) => {
                if (requestBody == null)
                {
                    serverRabbitMQ.Send(ea, ServerMessaging.BuildErrorResponse("Bad request formatting."));
                }
                try
                {
                    var response = BuildBill(requestBody);
                    serverRabbitMQ.Send(ea, response);
                }
                catch (Exception e)
                {
                    serverRabbitMQ.Send(ea, ServerMessaging.BuildErrorResponse(e.Message));
                }
            });
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
            serverRabbitMQ.Close();
        }
        /// <summary>
        /// Starts the dictionary cracking process.
        /// </summary>
        public static void RunCracking()
        {
            List <string>   usersRaw  = ServerMessaging.SetupPasswords();
            List <UserInfo> userInfos = PasswordHandler.ReadPasswordList(usersRaw);

            remainingPasswords = userInfos.Count;
            List <UserInfoClearText> result = new List <UserInfoClearText>();

            while (ServerMessaging.SetupValidChunk())
            {
                foreach (string line in Client.Instance.Chunk)
                {
                    IEnumerable <UserInfoClearText> partialResult = CheckVariations.CheckWordWithVariations(line, userInfos);
                    result.AddRange(partialResult);
                    remainingPasswords -= partialResult.Count();
                }
                if (result.Count > 0)
                {
                    ServerMessaging.WriteResults(result);
                }
                result = new List <UserInfoClearText>();
            }
        }
 public LobbyManager(ServerMessaging serverMessaging, ConnectedPlayers connectedPlayers)
 {
     _serverMessaging = serverMessaging;
     SetupPlayers(connectedPlayers);
 }
 public static void SendResponse(ServerResponseMessage response, ServerRequestMessage request)
 {
     response.RequestId = request.RequestId;
     ServerMessaging.Send(response, ServerManager.GetSocket(request.SenderType, request.SenderId));
 }
Exemple #17
0
 public static void SendMessage(ServerMessage message, ServerSocket socket)
 {
     ServerMessaging.Send(message, socket);
 }
 public void SendMessage(ServerMessage message)
 {
     this.m_pushSocket.SendFrame(ServerMessaging.WriteMessage(message));
 }
Exemple #19
0
 public static void SendMessage(ServerMessage message, int serverType, int serverId)
 {
     ServerMessaging.Send(message, ServerManager.GetSocket(serverType, serverId));
 }
Exemple #20
0
 public static void SendMessage(ServerAccountMessage message, int serverType)
 {
     ServerMessaging.Send(message, ServerManager.GetDocumentSocket(serverType, message.AccountId));
 }