Example #1
0
        private void btnClient_Click(object sender, EventArgs e)
        {
            OpenClose();
            PClient form = new PClient();

            form.ShowDialog();
        }
Example #2
0
 public override void OnException(PClient player, Exception ex)
 {
     WriteConsole.WriteLine("[BOT_EXCEPTION]: {0}", ex.ToString(), ConsoleColor.Red);
     OnDisconnectBot(player);
     Console.ReadKey();
     Environment.Exit(0);
 }
Example #3
0
        internal static async Task HandleQueue()
        {
            int delay = 1000;

            while (true)
            {
                try {
                    List <TSelect> queue = DataAccess.Get_Transactions();
                    foreach (TSelect select in queue)
                    {
                        var form = new NFrom()
                        {
                            Uri        = select.config.uri,
                            Headers    = select.config.headers,
                            HttpMethod = select.config.method,
                            Body       = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(select.transaction))
                        };
                        DataAccess.Set_Status_Queue(select.queue.id, Queue.Status.Execution);
                        await PClient.QProduce(select.queue.id, JsonConvert.SerializeObject(form));
                    }
                } catch (Exception e) {
                    Console.Out.WriteLine($"Could not catch the queue: {e.Message}, {e.StackTrace}");
                } finally {
                    await Task.Delay(delay);
                }
            }
        }
        public void UIInit(PClient parent)
        {
            this.Parent = parent;

            parent.SongPlayed += new SongEventHandler(parent_SongPlayed);

            this.Show();
        }
Example #5
0
 /// <summary>
 /// 关闭客户端,若为客户端模式,取消模式
 /// </summary>
 public static void AbortClient()
 {
     if (NetworkClient != null)
     {
         NetworkClient.Stop();
         _NetworkClient = null;
     }
     if (CurrentHostType.Equals(PHostType.Client))
     {
         CurrentHostType = PHostType.NoType;
     }
 }
Example #6
0
 /// <summary>
 /// 创建一个客户端,如果之前为服务器则将其关闭
 /// </summary>
 /// <param name="ServerIP">服务器的IP地址</param>
 /// <param name="Nickname">客户端的昵称</param>
 /// <returns>是否创建成功(IP地址正确、昵称长度不大于8且网络正常)</returns>
 public static bool CreateClient(string ServerIP, string Nickname)
 {
     if (Nickname.Length > PNetworkConfig.MaxNicknameLength)
     {
         return(false);
     }
     AbortServer();
     try {
         CurrentHostType = PHostType.Client;
         _NetworkClient  = new PClient(new TcpClient(ServerIP, PNetworkConfig.ServerPort));
     } catch {
         return(false);
     }
     CurrentNickname = Nickname;
     return(true);
 }
Example #7
0
 /// <summary>
 /// 关闭服务器(及其关联的客户端),如果不为服务器模式则不操作
 /// </summary>
 public static void AbortServer()
 {
     if (CurrentHostType.Equals(PHostType.Server))
     {
         if (NetworkClient != null)
         {
             NetworkClient.Stop();
             _NetworkClient = null;
         }
         if (NetworkServer != null)
         {
             NetworkServer.Close();
             _NetworkServer = null;
         }
         CurrentHostType = PHostType.NoType;
     }
 }
Example #8
0
 /// <summary>
 /// 建立服务器,同时建立和它连接的客户端
 /// </summary>
 /// <param name="GameMap">游戏地图</param>
 /// <param name="GameMode">游戏模式</param>
 public static void CreateServer(PMap GameMap, PMode GameMode)
 {
     AbortClient();
     CurrentHostType = PHostType.Server;
     PThread.Async(() => {
         _NetworkServer = new PServer()
         {
             maxConnectionNumber = GameMode.PlayerNumber,
             Game = new PGame(GameMap, GameMode)
         };
         Thread.Sleep(PNetworkConfig.ListenerInterval);
         try {
             _NetworkClient = new PClient(new TcpClient(PNetworkConfig.IP.ToString(), PNetworkConfig.ServerPort));
         } catch (Exception e) {
             PLogger.Log("服务器客户端创建错误");
             PLogger.Log(PNetworkConfig.IP.ToString());
             PLogger.Log(e.ToString());
         }
         CurrentNickname = PNetworkConfig.DefaultNickname;
     });
 }
Example #9
0
 private void saveButton_Click(object sender, EventArgs e)
 {
     if (isPhys)
     {
         if (!Utils.IsNotEmptyTextInputs(pSurname, pName, pPatronymic, pAddress, pMobile, pEmail) ||
             !Utils.IsValidFullName(pSurname, pName, pPatronymic) ||
             !Utils.IsValidMobile(pMobile) ||
             !Utils.IsValidEmail(pEmail))
         {
             return;
         }
         pClient = new PClient(
             pSurname.Text,
             pName.Text,
             pPatronymic.Text,
             pAddress.Text,
             Convert.ToInt64(pMobile.Text),
             pEmail.Text
             );
     }
     else
     {
         if (!Utils.IsNotEmptyTextInputs(lName, lAddress, lMobile, lEmail) ||
             !Utils.IsValidMobile(lMobile) ||
             !Utils.IsValidEmail(lEmail))
         {
             return;
         }
         lClient = new LClient(
             lName.Text,
             lAddress.Text,
             Convert.ToInt64(lMobile.Text),
             lEmail.Text
             );
     }
     IsSaved = true;
     this.Close();
 }
Example #10
0
 public EditClientsForm(bool isPhys, DataGridViewRow row) : this(isPhys)
 {
     if (isPhys)
     {
         pClient = new PClient(
             (string)row.Cells[0].Value,
             (string)row.Cells[1].Value,
             (string)row.Cells[2].Value,
             (string)row.Cells[3].Value,
             (long)row.Cells[4].Value,
             (string)row.Cells[5].Value
             );
     }
     else
     {
         lClient = new LClient(
             (string)row.Cells[0].Value,
             (string)row.Cells[1].Value,
             (long)row.Cells[2].Value,
             (string)row.Cells[3].Value
             );
     }
 }
Example #11
0
        public static string GetClientName(Contract contract)
        {
            string query = $@"WHERE {Db.Purchase.clientId} = (SELECT {Db.Purchase.clientId} FROM {Db.Purchase.title} 
WHERE {Db.id} = {contract.OrderId});";

            if (contract.IsPhClient())
            {
                query = $"SELECT * FROM {Db.PClients.title} {query}";
                using (var read = DatabaseService.ExecuteAndReturn(query))
                {
                    if (read.Read())
                    {
                        var pClient = new PClient(
                            (string)read.GetValue(read.GetOrdinal(Db.PClients.surname)),
                            (string)read.GetValue(read.GetOrdinal(Db.PClients.name)),
                            (string)read.GetValue(read.GetOrdinal(Db.PClients.patronymic)),
                            null,
                            0,
                            null);
                        return(pClient.GetShortName());
                    }
                }
            }
            else
            {
                query = $"SELECT * FROM {Db.LClients.title} {query}";
                using (var read = DatabaseService.ExecuteAndReturn(query))
                {
                    if (read.Read())
                    {
                        return((string)read.GetValue(read.GetOrdinal(Db.LClients.name)));
                    }
                }
            }

            return(null);
        }
Example #12
0
    static void PollConsole()
    {
        while (running)
        {
            Console.Write("Command > ");
            string[] args = Console.ReadLine().Split(' ');

            if (args[0] == "stop")
            {
                Console.WriteLine("Stopping client...");
                running = false;
            }

            if (args[0] == "connect")
            {
                Console.WriteLine("Connecting to masterserver...");
                server = client.Connect("localhost", 9100);
                Thread.Sleep(1000);
                Console.WriteLine("Connection state : " + server.ConnectionState);
            }

            if (args[0] == "join")
            {
                bool ranked = (args[1] == "r");
                if (ranked)
                {
                    Console.WriteLine("Joining ranked match.");
                }
                else
                {
                    Console.WriteLine("Joining normal match.");
                }
                server.Send(PClient.JoinQueue(ranked), SendOptions.ReliableOrdered);
            }
        }
    }
Example #13
0
 public abstract void OnException(PClient player, Exception ex);
Example #14
0
 public override void OnDisconnectBot(PClient player)
 {
     WriteConsole.WriteLine($"[BOT_{player.ServerType}_DISCONNECT]: {player.GetNickname}", ConsoleColor.Red);
     player.SendBytes(new byte[0]);
     player.Tcp.Close();
 }
 public void Start(PClient parent)
 {
     lyrics = new LyricsWindow();
     lyrics.UIInit(parent);
 }
Example #16
0
        public static void Server_OnPacketReceived(PClient player, ClientPacket packet)
        {
            var client = (ProjectG)player;

            client.HandleTypeClient(packet);
        }
Example #17
0
 public abstract void OnDisconnectBot(PClient player);