Exemplo n.º 1
0
        public void OnDirectIntroduce(int userId, MyRelayedConnection relayedConnection)
        {
            Debug.Assert(m_playersToIntroduce != null);

            MyPlayerRemote player;
            if(m_playersToIntroduce.TryGetValue(userId, out player))
            {
                if(player.Connection == null)
                {
                    player.Connection = relayedConnection;
                    player.Connection.Tag = player;
                }
            }
        }
Exemplo n.º 2
0
        public MyRelayedConnection GetRelayedConnection(IPEndPoint targetEp)
        {
            MyRelayedConnection connection;

            if (!m_relayedConnections.TryGetValue(targetEp, out connection))
            {
                connection = new MyRelayedConnection(this)
                {
                    RelayTargetEp = targetEp
                };
                m_relayedConnections[targetEp] = connection;
            }
            return(connection);
        }
Exemplo n.º 3
0
        public NetSendResult Send <T>(ref T evnt, NetConnection connection, NetDeliveryMethod deliveryMethod, int sequenceChannel, int maxSize = DEFAULT_MAX_SIZE)
            where T : struct, IMyEvent
        {
            NetOutgoingMessage  msg;
            MyRelayedConnection relayedConnection = connection as MyRelayedConnection;

            if (relayedConnection != null)
            {
                if (RelayServerConnection == null)
                {
                    //RaisePeerDisconnected(connection);
                    return(NetSendResult.FailedNotConnected);
                }

                maxSize += sizeof(byte); // Event type enum
                maxSize += 16;           // 16B for IPv6 addr
                maxSize += sizeof(int);  // Port

                msg = CreateMessage(maxSize);

                // Write relay header
                msg.Write((byte)MyEventEnum.RELAY);
                msg.Write(relayedConnection.RelayTargetEp);

                connection = RelayServerConnection;
            }
            else
            {
                msg = CreateMessage(maxSize);
            }

            Write(msg, evnt);
            if (CanEnqueue(connection.Status))
            {
                m_messageQueue.Add(new MyMessageQueueItem()
                {
                    Message = msg, DeliveryMethod = deliveryMethod, SequenceChannel = sequenceChannel, EndPoint = connection.RemoteEndpoint
                });
                return(NetSendResult.Queued);
            }
            else
            {
                return(connection.SendMessage(msg, deliveryMethod, sequenceChannel));
            }
        }