Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
 public static void WriteToServer(TcpClients client, byte[] message)
 {
     try
     {
         client.tcpClient.GetStream().Write(message, 0, message.Length);
     }
     catch { }
 }
Ejemplo n.º 3
0
 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)));
 }
Ejemplo n.º 4
0
 public static void SearchingResponse(TcpClients client)
 {
     SocketHelper.WriteToServer(client, Encapsulation.Serialize(Encapsulation.FromValue(new GenericMessage {
         Message = "Looking for a game"
     }, MessageType.Searching)));
 }
Ejemplo n.º 5
0
 public static void DiscoverResponse(TcpClients client)
 {
     SocketHelper.WriteToServer(client, Encapsulation.Serialize(Encapsulation.FromValue(new Discover {
         UserName = Environment.UserName
     }, MessageType.Discover)));
 }
Ejemplo n.º 6
0
 public static void DisconnectMessage(TcpClients client)
 {
     SocketHelper.WriteToServer(client, Encapsulation.Serialize(Encapsulation.FromValue(new GenericMessage {
         Message = "Disconnect"
     }, MessageType.Disconnect)));
 }
Ejemplo n.º 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);
        }