Exemplo n.º 1
0
        public static NetSendResult Send(KulamiPeer peer, Packet packet)
        {
            NetOutgoingMessage message = Client.CreateMessage();

            message.Write(packet);

            return(Client.SendMessage(message, peer.Connection, NetDeliveryMethod.ReliableOrdered, 0));
        }
Exemplo n.º 2
0
 public NetworkPlayer(KulamiPeer peer)
 {
     this.Peer           = peer;
     move                = Move.None;
     lastMove            = Move.None;
     peer.OnPlayerMove  += on_move_received;
     peer.OnChatMessage += on_chat_received;
     Name                = peer.Name;
 }
Exemplo n.º 3
0
        private static void on_received_mesage(object sender)
        {
            NetIncomingMessage incomingMessage = Client.ReadMessage();

            switch (incomingMessage.MessageType)
            {
            case NetIncomingMessageType.DiscoveryRequest:
                //TraceHelper.WriteLine("Request from {0}", incomingMessage.SenderEndPoint);

                //This message is received by the sender of the DiscoveryRequest
                //as of type DiscoveryResponse
                Client.SendDiscoveryResponse(null, incomingMessage.SenderEndPoint);
                break;

            case NetIncomingMessageType.DiscoveryResponse:
                //TraceHelper.WriteLine("Response from {0}", incomingMessage.SenderEndPoint);

                // See if we have a connection from the SenderEndPoint
                // If we don't, try to connect.

                // todo fix already connected error
                var connection = Client.GetConnection(incomingMessage.SenderEndPoint);
                if (connection == null)
                {
                    Client.Connect(incomingMessage.SenderEndPoint);
                }
                break;

            case NetIncomingMessageType.Data:
                HandleData(incomingMessage);
                break;

            case NetIncomingMessageType.StatusChanged:
                NetConnectionStatus status = (NetConnectionStatus)incomingMessage.ReadByte();
                if (status == NetConnectionStatus.Disconnected)
                {
                    if (Peers.ContainsKey(incomingMessage.SenderConnection.RemoteUniqueIdentifier))
                    {
                        KulamiPeer peer = Peers[incomingMessage.SenderConnection.RemoteUniqueIdentifier];
                        if (peer != null)
                        {
                            peer.Disconnect();
                        }
                    }
                }
                if (status == NetConnectionStatus.Connected)
                {
                    AddConnection(incomingMessage.SenderConnection);
                }
                break;
            }
        }
Exemplo n.º 4
0
        public static void on_peer_discovery(object sender, EventArgs e)
        {
            KulamiPeer peer = sender as KulamiPeer;

            if (peer == null)
            {
                return;
            }
            if (Peers.Contains(peer))
            {
                return;
            }

            Peers.Add((KulamiPeer)sender);
        }
Exemplo n.º 5
0
        private static void AddConnection(NetConnection connection)
        {
            TraceHelper.WriteLine("RUI: {0}", connection.RemoteUniqueIdentifier);
            KulamiPeer peer;

            if (!Peers.ContainsKey(connection.RemoteUniqueIdentifier))
            {
                peer = new KulamiPeer(connection);
                Peers[connection.RemoteUniqueIdentifier] = peer;

                if (OnDiscovery != null)
                {
                    OnDiscovery(peer, new EventArgs());
                }
            }
            else
            {
                Peers[connection.RemoteUniqueIdentifier].Connection = connection;
            }

            peer = Peers[connection.RemoteUniqueIdentifier];
            peer.SendName();
            peer.SendLobby();
        }