Ejemplo n.º 1
0
 protected virtual void OnMessageReceived(MessageReceivedEventArgs e)
 {
     EventHandler<MessageReceivedEventArgs> handler = MessageReceived;
     if(handler != null)
     {
         handler(this, e);
     }
 }
Ejemplo n.º 2
0
 void networkingManager_MessageReceived(object sender, MessageReceivedEventArgs e)
 {
     switch(e.Message.Type)
     {
         case NetworkMessage.MessageType.ClientGameResults:
             GameResults.Add(e.Sender, (int)e.Message.Content);
             break;
     }
 }
Ejemplo n.º 3
0
 void networkingManager_MessageReceived(object sender, BlockPartyShared.MessageReceivedEventArgs e)
 {
     if (e.Message.Type == BlockPartyShared.NetworkMessage.MessageType.ServerGameState &&
         (string)e.Message.Content == "Results")
     {
         NetworkingManager.Send(new NetworkMessage(NetworkMessage.MessageType.ClientResults, Score.GameScore));
         ScoreManager.LatestScore = Score.GameScore;
         serverGameStateChanged   = true;
     }
 }
Ejemplo n.º 4
0
    void networkingManager_MessageReceived(object sender, BlockPartyShared.MessageReceivedEventArgs e)
    {
        if (e.Message.Type == BlockPartyShared.NetworkMessage.MessageType.ServerGameState &&
            (string)e.Message.Content == "Game")
        {
            serverGameStateChanged = true;
        }

        if (e.Message.Type == BlockPartyShared.NetworkMessage.MessageType.ServerLeaderboard)
        {
            ScoreManager.SortedGameResults = (List <KeyValuePair <string, int> >)e.Message.Content;
        }
    }
Ejemplo n.º 5
0
        void Receive(object parameter)
        {
            TcpClient client = (TcpClient)parameter;
            NetworkStream stream = client.GetStream();

            while(true)
            {
                try
                {
                    NetworkMessage message = (NetworkMessage)formatter.Deserialize(stream);
                    Console.WriteLine("Received message from client {0}: {1}", client.Client.RemoteEndPoint.ToString(), message.ToString());

                    // process message
                    MessageReceivedEventArgs args = new MessageReceivedEventArgs();
                    args.Message = message;
                    args.Sender = client.Client.RemoteEndPoint.ToString();
                    OnMessageReceived(args);
                }
                catch(IOException e)
                {
                    Console.WriteLine("Client disconnected from {0}", client.Client.RemoteEndPoint.ToString());
                    clients.Remove(client);
                    client.Close();
                    return;
                }
            }
        }