Exemple #1
0
        public static void MessageProcessor(Form form, Encapsulation message, TcpClients client)
        {
            switch (message.MessageType)
            {
            case MessageType.Discover:
                Response.DiscoverResponse(client);
                Thread.Sleep(1000);
                toogleMatchMaking_View(form);
                Response.SearchingResponse(client);
                break;

            case MessageType.Disconnect:
                Environment.Exit(0);
                break;

            case MessageType.GameInfo:
                setGameInfo(message);
                toogleGame_View(form, true);
                break;

            case MessageType.NextRound:
                toogleGame_View(form, true);
                setNextRoundInfo(form, message);
                break;

            case MessageType.GameEnd:
                gameEndProcessor(form, message);
                break;
            }
        }
Exemple #2
0
 public static void WriteToServer(TcpClients client, byte[] message)
 {
     try
     {
         client.tcpClient.GetStream().Write(message, 0, message.Length);
     }
     catch { }
 }
 public static void AnswerResponse(TcpClients client, Choice playerChoice, int TimeToAnswer)
 {
     SocketHelper.WriteToServer(client, Encapsulation.Serialize(Encapsulation.FromValue(new Answer {
         GameId = GameInfo.UniqueId, RoundId = GameInfo.RoundGuid, TimeToAnswer = TimeToAnswer, playerChoice = playerChoice
     }, MessageType.Answer)));
 }
 public static void SearchingResponse(TcpClients client)
 {
     SocketHelper.WriteToServer(client, Encapsulation.Serialize(Encapsulation.FromValue(new GenericMessage {
         Message = "Looking for a game"
     }, MessageType.Searching)));
 }
 public static void DiscoverResponse(TcpClients client)
 {
     SocketHelper.WriteToServer(client, Encapsulation.Serialize(Encapsulation.FromValue(new Discover {
         UserName = Environment.UserName
     }, MessageType.Discover)));
 }
 public static void DisconnectMessage(TcpClients client)
 {
     SocketHelper.WriteToServer(client, Encapsulation.Serialize(Encapsulation.FromValue(new GenericMessage {
         Message = "Disconnect"
     }, MessageType.Disconnect)));
 }
Exemple #7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Config config = new Config($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\client.ini");

            _client = new TcpClients(config.serverIpAddress, config.serverPort);
        }