示例#1
0
 public ReplicaReturnResult ReceiveScopeChange(BitStream inBitStream, SystemAddress systemAddress, uint timestamp)
 {
     bool inScope;
     inBitStream.Read(out inScope);
     if (inScope)
         Console.Write("Received message that scope is now true in Player\n");
     else
         Console.Write("Received message that scope is now false in Player\n");
     return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
 }
示例#2
0
        public ReplicaReturnResult Deserialize(BitStream inBitStream, uint timestamp, uint lastDeserializeTime, SystemAddress systemAddress)
        {
            if (lastDeserializeTime == 0)
                Console.Write("First call to Player::Deserialize\n");
            else
                Console.Write("Got Player::Deserialize\n");

            inBitStream.Read(out position);
            inBitStream.Read(out health);
            return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
        }
 public void QueryTable(string tableName, string queryPassword, string[] columnNamesSubset, byte numColumnSubset, DatabaseFilter [] filter, byte numFilters, uint[] rowIds, byte numRowIDs, SystemAddress systemAddress, bool broadcast)
 {
     RakNetListDatabaseFilter filtersList =null;
     if (filter!=null)
     {
         filtersList = new RakNetListDatabaseFilter();
         int listLen = filter.Length;
         for (int i = 0; i < listLen; i++)
         {
      	 		    filtersList.Insert(filter[i], "", 1);
         }
     }
     QueryTableHelper(tableName, queryPassword, columnNamesSubset, numColumnSubset, filtersList, numFilters, rowIds, numRowIDs, systemAddress, broadcast);
 }
 public void UpdateRow(string tableName, string updatePassword, RowUpdateMode updateMode, bool hasRowId, uint rowId, DatabaseCellUpdate [] cellUpdates, byte numCellUpdates, SystemAddress systemAddress, bool broadcast)
 {
     RakNetListDatabaseCellUpdate cellUpdateList =null;
     if (cellUpdates!=null)
     {
         cellUpdateList = new RakNetListDatabaseCellUpdate();
         int listLen = cellUpdates.Length;
         for (int i = 0; i < listLen; i++)
         {
      	 		    cellUpdateList.Insert(cellUpdates[i], "", 1);
         }
     }
     UpdateRowHelper(tableName, updatePassword, updateMode, hasRowId, rowId, cellUpdateList, numCellUpdates, systemAddress, broadcast);
 }
示例#5
0
        static ReplicaReturnResult ConstructionCB(BitStream inBitStream, uint timestamp, NetworkID networkID, NetworkIDObject existingObject, SystemAddress senderId, ReplicaManagerExt caller, IntPtr userData)
        {
            StringBuilder output = new StringBuilder(255);

            if (isServer)
                return ReplicaReturnResult.REPLICA_PROCESSING_DONE;

            StringTable.Instance().DecodeString(output, output.Capacity, inBitStream);
            if (output.ToString() == "Player")
            {
                System.Diagnostics.Debug.Assert(player == null);

                player = new Player();

                player.replica.SetNetworkIDManager(networkIDManager);
                player.replica.SetNetworkID(networkID);

                if (!isServer)
                {
                    replicaManager.Construct(player.replica, true, senderId, false);

                    replicaManager.SetScope(player.replica, true, senderId, false);
                }

                Console.Write("New player created\n");
            }
            else if (output.ToString() == "Monster")
            {
                System.Diagnostics.Debug.Assert(monster == null);

                monster = new Monster();

                monster.replica.SetNetworkIDManager(networkIDManager);
                monster.replica.SetNetworkID(networkID);

                if (!isServer)
                {
                    replicaManager.Construct(monster.replica, true, senderId, false);

                    replicaManager.SetScope(monster.replica, true, senderId, false);
                }

                Console.Write("New monster created\n");
            }
            else
            {
                System.Diagnostics.Debug.Assert(false);
            }
            return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
        }
        public void SendEvent(SystemAddress systemAddress, bool broadcast, IEvent e)
        {
            PacketPriority priority = PacketPriority.HIGH_PRIORITY;
            PacketReliability reliability = PacketReliability.RELIABLE_ORDERED;
            byte orderingChannel = 0;
            uint shiftTimestamp = 0;

            logger.Debug("sending an event: [{0}]", e.ToString());

            bool result = RakPeerInterface.RPC(
                e.ProtocolInfo.Name,
                e.Stream, priority, reliability, orderingChannel,
                systemAddress, broadcast, shiftTimestamp,
                RakNetBindings.UNASSIGNED_NETWORK_ID, null);

            if (!result)
                logger.Debug("could not send data!");
            else
                logger.Debug("sent data.");
        }
示例#7
0
    public void UpdateRow(string tableName, string updatePassword, RowUpdateMode updateMode, bool hasRowId, uint rowId, DatabaseCellUpdate [] cellUpdates, byte numCellUpdates, SystemAddress systemAddress, bool broadcast)
    {
        RakNetListDatabaseCellUpdate cellUpdateList = null;

        if (cellUpdates != null)
        {
            cellUpdateList = new RakNetListDatabaseCellUpdate();
            int listLen = cellUpdates.Length;
            for (int i = 0; i < listLen; i++)
            {
                cellUpdateList.Insert(cellUpdates[i], "", 1);
            }
        }
        UpdateRowHelper(tableName, updatePassword, updateMode, hasRowId, rowId, cellUpdateList, numCellUpdates, systemAddress, broadcast);
    }
示例#8
0
 public virtual void OnForwardingInProgress(string proxyIPAddress, ushort proxyPort, SystemAddress proxyCoordinator, SystemAddress sourceAddress, SystemAddress targetAddress, RakNetGUID targetGuid, UDPProxyClient proxyClientPlugin)
 {
     RakNetPINVOKE.CSharp_RakNet_UDPProxyClientResultHandler_OnForwardingInProgress(swigCPtr, proxyIPAddress, proxyPort, SystemAddress.getCPtr(proxyCoordinator), SystemAddress.getCPtr(sourceAddress), SystemAddress.getCPtr(targetAddress), RakNetGUID.getCPtr(targetGuid), UDPProxyClient.getCPtr(proxyClientPlugin));
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#9
0
 private void UpdateRowHelper(string tableName, string updatePassword, RowUpdateMode updateMode, bool hasRowId, uint rowId, RakNetListDatabaseCellUpdate cellUpdates, byte numCellUpdates, SystemAddress systemAddress, bool broadcast)
 {
     RakNetPINVOKE.LightweightDatabaseClient_UpdateRowHelper(swigCPtr, tableName, updatePassword, (int)updateMode, hasRowId, rowId, RakNetListDatabaseCellUpdate.getCPtr(cellUpdates), numCellUpdates, SystemAddress.getCPtr(systemAddress), broadcast);
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#10
0
        public ReplicaReturnResult ReceiveDestruction(BitStream inBitStream, SystemAddress systemAddress, uint timestamp)
        {
            Program.player.Dispose();

            return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
        }
 private void UpdateRowHelper(string tableName, string updatePassword, RowUpdateMode updateMode, bool hasRowId, uint rowId, RakNetListDatabaseCellUpdate cellUpdates, byte numCellUpdates, SystemAddress systemAddress, bool broadcast)
 {
     RakNetPINVOKE.LightweightDatabaseClient_UpdateRowHelper(swigCPtr, tableName, updatePassword, (int)updateMode, hasRowId, rowId, RakNetListDatabaseCellUpdate.getCPtr(cellUpdates), numCellUpdates, SystemAddress.getCPtr(systemAddress), broadcast);
     if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve();
 }
示例#12
0
        public SystemAddress Pop()
        {
            SystemAddress ret = new SystemAddress(RakNetPINVOKE.RakNetListSystemAddress_Pop(swigCPtr), false);

            return(ret);
        }
 public virtual void SendCommandList(TransportInterface transport, SystemAddress systemAddress)
 {
     RakNetPINVOKE.CommandParserInterface_SendCommandList(swigCPtr, TransportInterface.getCPtr(transport), SystemAddress.getCPtr(systemAddress));
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public override ReplicaReturnResult Serialize(ref bool sendTimestamp, BitStream outBitStream, uint lastSendTime, ref PacketPriority priority, ref PacketReliability reliability, uint currentTime, SystemAddress systemAddress, SWIGTYPE_p_unsigned_int flags)
 {
     return Listener.Serialize(ref sendTimestamp, outBitStream, lastSendTime, ref priority, ref reliability, currentTime, systemAddress, flags);
 }
示例#15
0
        static void Main(string[] args)
        {
            if (!File.Exists("RakNet.dll"))
            {
                Console.WriteLine("The SWIG build of the DLL has not been copied to the executable directory\nCopy from Swig/SwigWindowsCSharpSample/SwigTestApp/bin/X86/Debug/RakNet.dll to\nSwigWindowsCSharpSample/SwigTestApp/bin/Debug/RakNet.dll\nPress enter to quit.");
                Console.Read();
                return;
            }

            try
            {
                RakString dllCallTest = new RakString();
            }
            catch (Exception e)
            {
                Console.WriteLine("DLL issue\nAdd SwigOutput/CplusDLLIncludes/RakNetWrap.cxx to the project\nDLL_Swig/RakNet.sln and rebuild.\nPress enter to quit.");
                Console.Read();
                return;
            }

            Packet    testPacket;
            int       loopNumber;
            BitStream stringTestSendBitStream    = new BitStream();
            BitStream rakStringTestSendBitStream = new BitStream();
            BitStream receiveBitStream           = new BitStream();
            String    holdingString;
            TimeSpan  startTimeSpan;
            RakString rakStringTest = new RakString();

            RakPeerInterface testClient = RakPeer.GetInstance();

            testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1);

            RakPeerInterface testServer = RakPeer.GetInstance();

            testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1);
            testServer.SetMaximumIncomingConnections(1);

            Console.WriteLine("Send and receive loop using BitStream.\nBitStream read done into RakString");

            testClient.Connect("127.0.0.1", 60001, "", 0);

            String sendString = "The test string";

            stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            stringTestSendBitStream.Write(sendString);

            RakString testRakString = new RakString("Test RakString");

            rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            rakStringTestSendBitStream.Write(testRakString);

            startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            loopNumber    = 0;

            while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
            {
                testPacket = testServer.Receive();
                if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                {
                    receiveBitStream.Reset();
                    receiveBitStream.Write(testPacket.data, testPacket.length);
                    receiveBitStream.IgnoreBytes(1);
                    receiveBitStream.Read(rakStringTest);
                    Console.WriteLine("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String());
                }
                testServer.DeallocatePacket(testPacket);
                loopNumber++;
                System.Threading.Thread.Sleep(50);
                testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
            }

            Console.WriteLine("String send and receive loop using BitStream.\nBitStream read done into String");

            SystemAddress[] remoteSystems;
            ushort          numberOfSystems = 1;

            testServer.GetConnectionList(out remoteSystems, ref numberOfSystems);

            startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            loopNumber    = 0;
            while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
            {
                testPacket = testServer.Receive();
                if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                {
                    receiveBitStream.Reset();
                    receiveBitStream.Write(testPacket.data, testPacket.length);
                    receiveBitStream.IgnoreBytes(1);
                    receiveBitStream.Read(out holdingString);
                    Console.WriteLine("Loop number: " + loopNumber + "\nData: " + holdingString);
                }
                testServer.DeallocatePacket(testPacket);
                loopNumber++;
                System.Threading.Thread.Sleep(50);
                SystemAddress sa = RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS;
                testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
            }
            //If RakString is not freed before program exit it will crash
            rakStringTest.Dispose();
            testRakString.Dispose();

            RakPeer.DestroyInstance(testClient);
            RakPeer.DestroyInstance(testServer);
            Console.WriteLine("Demo complete. Press Enter.");
            Console.Read();
        }
 public override ReplicaReturnResult SendDestruction(BitStream outBitStream, SystemAddress systemAddress, ref bool includeTimestamp)
 {
     return Listener.SendDestruction(outBitStream, systemAddress, ref includeTimestamp);
 }
 public override ReplicaReturnResult SendScopeChange(bool inScope, BitStream outBitStream, uint currentTime, SystemAddress systemAddress, ref bool includeTimestamp)
 {
     return Listener.SendScopeChange(inScope, outBitStream, currentTime, systemAddress, ref includeTimestamp);
 }
 public override ReplicaReturnResult SendConstruction(uint currentTime, SystemAddress systemAddress, SWIGTYPE_p_unsigned_int flags, BitStream outBitStream, ref bool includeTimestamp)
 {
     return Listener.SendConstruction(currentTime, systemAddress, flags, outBitStream, ref includeTimestamp);
 }
 public override ReplicaReturnResult ReceiveScopeChange(BitStream inBitStream, SystemAddress systemAddress, uint timestamp)
 {
     return Listener.ReceiveScopeChange(inBitStream, systemAddress, timestamp);
 }
 public override ReplicaReturnResult ReceiveDestruction(BitStream inBitStream, SystemAddress systemAddress, uint timestamp)
 {
     return Listener.ReceiveDestruction(inBitStream, systemAddress, timestamp);
 }
示例#21
0
 private void QueryTableHelper(string tableName, string queryPassword, string[] columnNamesSubset, byte numColumnSubset, RakNetListDatabaseFilter filter, byte numFilters, uint[] rowIds, byte numRowIDs, SystemAddress systemAddress, bool broadcast)
 {
     RakNetPINVOKE.LightweightDatabaseClient_QueryTableHelper(swigCPtr, tableName, queryPassword, columnNamesSubset, numColumnSubset, RakNetListDatabaseFilter.getCPtr(filter), numFilters, rowIds, numRowIDs, SystemAddress.getCPtr(systemAddress), broadcast);
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#22
0
        public bool RequestForwarding(SystemAddress proxyCoordinator, SystemAddress sourceAddress, RakNetGUID targetGuid, uint timeoutOnNoDataMS)
        {
            bool ret = RakNetPINVOKE.UDPProxyClient_RequestForwarding__SWIG_3(swigCPtr, SystemAddress.getCPtr(proxyCoordinator), SystemAddress.getCPtr(sourceAddress), RakNetGUID.getCPtr(targetGuid), timeoutOnNoDataMS);

            if (RakNetPINVOKE.SWIGPendingException.Pending)
            {
                throw RakNetPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#23
0
 public void Replace(SystemAddress input, SystemAddress filler, uint position, string file, uint line)
 {
     RakNetPINVOKE.RakNetListSystemAddress_Replace__SWIG_0(swigCPtr, SystemAddress.getCPtr(input), SystemAddress.getCPtr(filler), position, file, line);
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#24
0
        private string FormatLineHelper(string into, string dir, string type, uint packet, uint frame, string idToPrint, uint bitLen, ulong time, SystemAddress local, SystemAddress remote, uint splitPacketId, uint splitPacketIndex, uint splitPacketCount, uint orderingIndex)
        {
            string ret = RakNetPINVOKE.PacketLogger_FormatLineHelper__SWIG_1(swigCPtr, into, dir, type, packet, frame, idToPrint, bitLen, time, SystemAddress.getCPtr(local), SystemAddress.getCPtr(remote), splitPacketId, splitPacketIndex, splitPacketCount, orderingIndex);

            if (RakNetPINVOKE.SWIGPendingException.Pending)
            {
                throw RakNetPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
 public virtual void ReturnResult(string command, TransportInterface transport, SystemAddress systemAddress)
 {
     RakNetPINVOKE.CommandParserInterface_ReturnResult__SWIG_4(swigCPtr, command, TransportInterface.getCPtr(transport), SystemAddress.getCPtr(systemAddress));
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#26
0
 public virtual void FormatLine(ref string preInitializedStringBigEnoughToFitResult, string dir, string type, uint packet, uint frame, string idToPrint, uint bitLen, ulong time, SystemAddress local, SystemAddress remote, uint splitPacketId, uint splitPacketIndex, uint splitPacketCount, uint orderingIndex)
 {
     preInitializedStringBigEnoughToFitResult = FormatLineHelper(preInitializedStringBigEnoughToFitResult, dir, type, packet, frame, idToPrint, bitLen, time, local, remote, splitPacketId, splitPacketIndex, splitPacketCount, orderingIndex);
 }
 public override ReplicaReturnResult Deserialize(BitStream inBitStream, uint timestamp, uint lastDeserializeTime, SystemAddress systemAddress)
 {
     return Listener.Deserialize(inBitStream, timestamp, lastDeserializeTime, systemAddress);
 }
示例#28
0
 public override void OnReliabilityLayerNotification(string errorMessage, uint bitsUsed, SystemAddress remoteSystemAddress, bool isError)
 {
     RakNetPINVOKE.PacketLogger_OnReliabilityLayerNotification(swigCPtr, errorMessage, bitsUsed, SystemAddress.getCPtr(remoteSystemAddress), isError);
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#29
0
        public ReplicaReturnResult SendConstruction(uint currentTime, SystemAddress systemAddress, SWIGTYPE_p_unsigned_int flags, BitStream outBitStream, ref bool includeTimestamp)
        {
            StringTable.Instance().EncodeString("Player", 255, outBitStream);

            Program.replicaManager.SetScope(replica, true, systemAddress, false);

            Console.Write("Sending monster to {0}:{1}\n", systemAddress.binaryAddress, systemAddress.port);

            return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
        }
示例#30
0
        public bool RequestForwarding(SystemAddress proxyCoordinator, SystemAddress sourceAddress, SystemAddress targetAddressAsSeenFromCoordinator, uint timeoutOnNoDataMS)
        {
            bool ret = RakNetPINVOKE.CSharp_RakNet_UDPProxyClient_RequestForwarding__SWIG_1(swigCPtr, SystemAddress.getCPtr(proxyCoordinator), SystemAddress.getCPtr(sourceAddress), SystemAddress.getCPtr(targetAddressAsSeenFromCoordinator), timeoutOnNoDataMS);

            if (RakNetPINVOKE.SWIGPendingException.Pending)
            {
                throw RakNetPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
 public void SendEvent(SystemAddress targetAddress, IEvent e)
 {
     module.SendEvent(targetAddress, false, e);
 }
示例#32
0
        public bool RequestForwarding(SystemAddress proxyCoordinator, SystemAddress sourceAddress, RakNetGUID targetGuid, uint timeoutOnNoDataMS, BitStream serverSelectionBitstream)
        {
            bool ret = RakNetPINVOKE.CSharp_RakNet_UDPProxyClient_RequestForwarding__SWIG_2(swigCPtr, SystemAddress.getCPtr(proxyCoordinator), SystemAddress.getCPtr(sourceAddress), RakNetGUID.getCPtr(targetGuid), timeoutOnNoDataMS, BitStream.getCPtr(serverSelectionBitstream));

            if (RakNetPINVOKE.SWIGPendingException.Pending)
            {
                throw RakNetPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#33
0
        /// <summary>
        /// 处理接受消息
        /// </summary>
        void ReceiveMessage()
        {
            receiveCount = 0;
            // 单帧处理消息数量不大于指定的消息数量
            while (receiveCount < MaxReceiveCount || !ProcUserMessage)
            {
                if (mClient == null)
                {
                    Debug.LogErrorFormat("NetworkClient is null!");
                    break;
                }
                Packet packet = mClient.Receive();
                if (packet == null) // 没有消息内容了,不用解析,退出循环
                {
                    break;
                }
                receiveCount++;
                // DefaultMessageIDTypes messageIDType = (DefaultMessageIDTypes)packet.data[0];
                // LogMessage(messageIDType.ToString());
                switch (packet.data[0])
                {
                case (byte)DefaultMessageIDTypes.ID_CONNECTED_PING:             // 0
                case (byte)DefaultMessageIDTypes.ID_UNCONNECTED_PING:           // 1
                    LogMessage(string.Format("Ping from {0}", packet.systemAddress.ToString(true)));
                    break;

                case (byte)DefaultMessageIDTypes.ID_CONNECTION_REQUEST_ACCEPTED:        //16 连接成功
                {
                    IsConnecting      = false;
                    IsConnectedServer = true;
                    m_serverAddress   = packet.systemAddress;
                    m_guid            = packet.guid;
                    mClient.SetTimeoutTime(9000, m_serverAddress);
                    NotifyConnectCallBack(true);
                }
                break;

                case (byte)DefaultMessageIDTypes.ID_CONNECTION_ATTEMPT_FAILED:          // 17 连接失败(多种原因)
                    if (IsConnecting)
                    {
                        NotifyConnectCallBack(false);
                    }
                    DisConnect();
                    EventDispatcher.Instance.TriggerEvent("Application_ConnectionLost", packet.data[0]);
                    break;

                case (byte)DefaultMessageIDTypes.ID_ALREADY_CONNECTED:                  // 18 已经存在
                    //Debug.Log("收到18消息");
                    DisConnect();
                    EventDispatcher.Instance.TriggerEvent("Application_ConnectionLost", packet.data[0]);
                    break;

                case (byte)DefaultMessageIDTypes.ID_NO_FREE_INCOMING_CONNECTIONS:       // 20 服务器满员了
                    DisConnect();
                    EventDispatcher.Instance.TriggerEvent("Application_ConnectionLost", packet.data[0]);
                    // Sorry, the server is full.  I don't do anything here but
                    // A real app should tell the user
                    break;

                case (byte)DefaultMessageIDTypes.ID_DISCONNECTION_NOTIFICATION:         // 21 丢失通知
                    DisConnect();
                    EventDispatcher.Instance.TriggerEvent("Application_ConnectionLost", packet.data[0]);
                    break;

                case (byte)DefaultMessageIDTypes.ID_CONNECTION_LOST:                    // 22 连接关闭
                    // Couldn't deliver a reliable packet - i.e. the other system was abnormally
                    // terminated
                    //Debug.Log("收到22消息");
                    DisConnect();
                    EventDispatcher.Instance.TriggerEvent("Application_ConnectionLost", packet.data[0]);
                    break;

                case (byte)DefaultMessageIDTypes.ID_CONNECTION_BANNED:                  // 23 服务器维护,强壮踢出所有人
                    if (IsConnecting)
                    {
                        NotifyConnectCallBack(false);
                    }
                    DisConnect();
                    EventDispatcher.Instance.TriggerEvent("Application_ConnectionLost", packet.data[0]);
                    break;

                case (byte)DefaultMessageIDTypes.ID_INVALID_PASSWORD:                       // 24 无效的密码
                    break;

                case (byte)DefaultMessageIDTypes.ID_INCOMPATIBLE_PROTOCOL_VERSION:          // 25 无效协议
                    break;

                case (byte)DefaultMessageIDTypes.ID_REMOTE_DISCONNECTION_NOTIFICATION:      // 31
                    break;

                case (byte)DefaultMessageIDTypes.ID_REMOTE_CONNECTION_LOST:                 // 32
                    // Server telling the clients of another m_Client disconnecting forcefully.  You can manually broadcast this in a peer to peer enviroment if you want.
                    DisConnect();
                    EventDispatcher.Instance.TriggerEvent("Application_ConnectionLost", packet.data[0]);
                    break;

                case (byte)DefaultMessageIDTypes.ID_REMOTE_NEW_INCOMING_CONNECTION:         // 33
                    // Server telling the clients of another m_Client connecting.  You can manually broadcast this in a peer to peer enviroment if you want.
                    break;

                case (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM:                       // 134
                case (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM2:                      // 135
                    if (ProcUserMessage == true)
                    {
                        Dispatch(packet);
                    }
                    break;

                default:
                    // It's a m_Client, so just show the message
                    LogMessage("Message ID Type default: " + packet.data[0]);
                    break;
                }
                if (mClient != null)
                {
                    mClient.DeallocatePacket(packet);
                }
                else
                {
                    Debug.LogErrorFormat("DeallocatePacket NetworkClient:{0} is null!", ClientName);
                }
            }

            if (ProcUserMessage == false)
            {
                ProcUserMessage = true;
                // 抛出消息清除完毕的事件
                //Debug.Log("c#清空消息完毕");
                EventDispatcher.Instance.TriggerEvent("Application_ClearMessage_OK", null);
            }
        }
示例#34
0
    public void Update()
    {
        if (null == m_Socket)
        {
            return;
        }
        for (m_MessagePacket = m_Socket.Receive(); null != m_MessagePacket; m_Socket.DeallocatePacket(m_MessagePacket), m_MessagePacket = m_Socket.Receive())
        {
            // We got a packet, get the identifier with our handy function
            DefaultMessageIDTypes packetIdentifier = (DefaultMessageIDTypes)GetPacketIdentifier(m_MessagePacket);

            // Check if this is a network message packet
            switch (packetIdentifier)
            {
            case DefaultMessageIDTypes.ID_DISCONNECTION_NOTIFICATION:
                // Connection lost normally
                //printf("ID_DISCONNECTION_NOTIFICATION\n");
                OnDisconnected();
                break;

            case DefaultMessageIDTypes.ID_ALREADY_CONNECTED:
                // Connection lost normally
                //printf("ID_ALREADY_CONNECTED with guid %" PRINTF_64_BIT_MODIFIER "u\n", m_MessagePacket->guid);
                break;

            case DefaultMessageIDTypes.ID_INCOMPATIBLE_PROTOCOL_VERSION:
                //printf("ID_INCOMPATIBLE_PROTOCOL_VERSION\n");
                break;

            case DefaultMessageIDTypes.ID_REMOTE_DISCONNECTION_NOTIFICATION:     // Server telling the clients of another client disconnecting gracefully.  You can manually broadcast this in a peer to peer enviroment if you want.
                //printf("ID_REMOTE_DISCONNECTION_NOTIFICATION\n");
                break;

            case DefaultMessageIDTypes.ID_REMOTE_CONNECTION_LOST:     // Server telling the clients of another client disconnecting forcefully.  You can manually broadcast this in a peer to peer enviroment if you want.
                //printf("ID_REMOTE_CONNECTION_LOST\n");
                OnDisconnected();
                break;

            case DefaultMessageIDTypes.ID_REMOTE_NEW_INCOMING_CONNECTION:     // Server telling the clients of another client connecting.  You can manually broadcast this in a peer to peer enviroment if you want.
                //printf("ID_REMOTE_NEW_INCOMING_CONNECTION\n");
                break;

            case DefaultMessageIDTypes.ID_CONNECTION_BANNED:     // Banned from this server
                //printf("We are banned from this server.\n");
                break;

            case DefaultMessageIDTypes.ID_CONNECTION_ATTEMPT_FAILED:
                //printf("Connection attempt failed\n");
                OnDisconnected();
                break;

            case DefaultMessageIDTypes.ID_NO_FREE_INCOMING_CONNECTIONS:
                // Sorry, the server is full.  I don't do anything here but
                // A real app should tell the user
                //printf("ID_NO_FREE_INCOMING_CONNECTIONS\n");
                OnDisconnected();
                break;

            case DefaultMessageIDTypes.ID_INVALID_PASSWORD:
                //printf("ID_INVALID_PASSWORD\n");
                OnDisconnected();
                break;

            case DefaultMessageIDTypes.ID_CONNECTION_LOST:
                // Couldn't deliver a reliable packet - i.e. the other system was abnormally
                // terminated
                //printf("ID_CONNECTION_LOST\n");
                OnDisconnected();
                break;

            case DefaultMessageIDTypes.ID_CONNECTION_REQUEST_ACCEPTED:
                // This tells the client they have connected
                //printf("ID_CONNECTION_REQUEST_ACCEPTED to %s with GUID %s\n", m_MessagePacket->systemAddress.ToString(true), m_MessagePacket->guid.ToString());
                //printf("My external address is %s\n", m_Socket->GetExternalID(m_MessagePacket->systemAddress).ToString(true));
                m_SystemAddress = m_MessagePacket.systemAddress;
                OnConnected();
                break;

            case DefaultMessageIDTypes.ID_CONNECTED_PING:
            case DefaultMessageIDTypes.ID_UNCONNECTED_PING:
                //printf("Ping from %s\n", m_MessagePacket->systemAddress.ToString(true));
                break;

            default:
                // It's a client, so just show the message
                //printf("%s\n", p->data);
                if (null != m_Stream)
                {
                    m_Stream.OnParseMessage();
                }
                break;
            }
        }
    }
示例#35
0
    public void QueryTable(string tableName, string queryPassword, string[] columnNamesSubset, byte numColumnSubset, DatabaseFilter [] filter, byte numFilters, uint[] rowIds, byte numRowIDs, SystemAddress systemAddress, bool broadcast)
    {
        RakNetListDatabaseFilter filtersList = null;

        if (filter != null)
        {
            filtersList = new RakNetListDatabaseFilter();
            int listLen = filter.Length;
            for (int i = 0; i < listLen; i++)
            {
                filtersList.Insert(filter[i], "", 1);
            }
        }
        QueryTableHelper(tableName, queryPassword, columnNamesSubset, numColumnSubset, filtersList, numFilters, rowIds, numRowIDs, systemAddress, broadcast);
    }
示例#36
0
 public void FindRouterPortStride(SystemAddress facilitator)
 {
     RakNetPINVOKE.CSharp_RakNet_NatPunchthroughClient_FindRouterPortStride(swigCPtr, SystemAddress.getCPtr(facilitator));
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#37
0
 public void RemoveRow(string tableName, string removePassword, uint rowId, SystemAddress systemAddress, bool broadcast)
 {
     RakNetPINVOKE.LightweightDatabaseClient_RemoveRow(swigCPtr, tableName, removePassword, rowId, SystemAddress.getCPtr(systemAddress), broadcast);
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#38
0
        public bool OpenNAT(RakNetGUID destination, SystemAddress facilitator)
        {
            bool ret = RakNetPINVOKE.CSharp_RakNet_NatPunchthroughClient_OpenNAT(swigCPtr, RakNetGUID.getCPtr(destination), SystemAddress.getCPtr(facilitator));

            if (RakNetPINVOKE.SWIGPendingException.Pending)
            {
                throw RakNetPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
 public virtual void OnConnectionLost(SystemAddress systemAddress, TransportInterface transport)
 {
     RakNetPINVOKE.CSharp_RakNet_CommandParserInterface_OnConnectionLost(swigCPtr, SystemAddress.getCPtr(systemAddress), TransportInterface.getCPtr(transport));
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#40
0
 public void GetUPNPPortMappings(string externalPort, string internalPort, SystemAddress natPunchthroughServerAddress)
 {
     RakNetPINVOKE.CSharp_RakNet_NatPunchthroughClient_GetUPNPPortMappings(swigCPtr, externalPort, internalPort, SystemAddress.getCPtr(natPunchthroughServerAddress));
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#41
0
        public SystemAddress Get(uint position)
        {
            SystemAddress ret = new SystemAddress(RakNetPINVOKE.RakNetListSystemAddress_Get(swigCPtr, position), false);

            return(ret);
        }
示例#42
0
        static void Main(string[] args)
        {
            Packet    testPacket;
            int       loopNumber;
            BitStream stringTestSendBitStream    = new BitStream();
            BitStream rakStringTestSendBitStream = new BitStream();
            BitStream receiveBitStream           = new BitStream();
            String    holdingString;
            TimeSpan  startTimeSpan;
            RakString rakStringTest = new RakString();

            RakPeerInterface testClient = RakPeer.GetInstance();

            testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1);

            RakPeerInterface testServer = RakPeer.GetInstance();

            testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1);
            testServer.SetMaximumIncomingConnections(1);

            Console.WriteLine("Send and receive loop using BitStream.\nBitStream read done into RakString");

            testClient.Connect("127.0.0.1", 60001, "", 0);

            String sendString = "The test string";

            stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            stringTestSendBitStream.Write(sendString);

            RakString testRakString = new RakString("Test RakString");

            rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            rakStringTestSendBitStream.Write(testRakString);

            startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            loopNumber    = 0;

            while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
            {
                testPacket = testServer.Receive();
                if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                {
                    receiveBitStream.Reset();
                    receiveBitStream.Write(testPacket.data, testPacket.length);
                    receiveBitStream.IgnoreBytes(1);
                    receiveBitStream.Read(rakStringTest);
                    Console.WriteLine("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String());
                }
                testServer.DeallocatePacket(testPacket);
                loopNumber++;
                System.Threading.Thread.Sleep(50);
                testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
            }

            Console.WriteLine("String send and receive loop using BitStream.\nBitStream read done into String");

            SystemAddress[] remoteSystems;
            ushort          numberOfSystems = 1;

            testServer.GetConnectionList(out remoteSystems, ref numberOfSystems);

            startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            loopNumber    = 0;
            while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
            {
                testPacket = testServer.Receive();
                if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                {
                    receiveBitStream.Reset();
                    receiveBitStream.Write(testPacket.data, testPacket.length);
                    receiveBitStream.IgnoreBytes(1);
                    receiveBitStream.Read(out holdingString);
                    Console.WriteLine("Loop number: " + loopNumber + "\nData: " + holdingString);
                }
                testServer.DeallocatePacket(testPacket);
                loopNumber++;
                System.Threading.Thread.Sleep(50);
                SystemAddress sa = RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS;
                testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
            }
            //If RakString is not freed before program exit it will crash
            rakStringTest.Dispose();
            testRakString.Dispose();

            RakPeer.DestroyInstance(testClient);
            RakPeer.DestroyInstance(testServer);
            Console.WriteLine("Demo complete. Press Enter.");
            Console.Read();
        }
示例#43
0
        protected RaknetIPAddress GetMyAddress()
        {
            SystemAddress systemAddress = rakPeer.GetMyBoundAddress();

            return(new RaknetIPAddress(systemAddress.ToString(false), systemAddress.GetPort()));
        }
示例#44
0
 public ReplicaReturnResult SendDestruction(BitStream outBitStream, SystemAddress systemAddress, ref bool includeTimestamp)
 {
     return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
 }
        public virtual bool OnCommand(string command, uint numParameters, string[] parameterList, TransportInterface transport, SystemAddress systemAddress, string originalString)
        {
            bool ret = RakNetPINVOKE.CommandParserInterface_OnCommand(swigCPtr, command, numParameters, parameterList, TransportInterface.getCPtr(transport), SystemAddress.getCPtr(systemAddress), originalString);

            if (RakNetPINVOKE.SWIGPendingException.Pending)
            {
                throw RakNetPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#46
0
        public ReplicaReturnResult Serialize(ref bool sendTimestamp, BitStream outBitStream, uint lastSendTime, ref PacketPriority priority, ref PacketReliability reliability, uint currentTime, SystemAddress systemAddress, SWIGTYPE_p_unsigned_int flags)
        {
            if (lastSendTime == 0)
                Console.Write("First call to Player::Serialize for {0}:{1}\n", systemAddress.binaryAddress, systemAddress.port);

            outBitStream.Write(position);
            outBitStream.Write(health);
            return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
        }
示例#47
0
        public SystemAddress GetConnectedHostAddr()
        {
            SystemAddress ret = new SystemAddress(RakNetPINVOKE.FullyConnectedMesh2_GetConnectedHostAddr(swigCPtr), true);

            return(ret);
        }
示例#48
0
 public ReplicaReturnResult SendScopeChange(bool inScope, BitStream outBitStream, uint currentTime, SystemAddress systemAddress, ref bool includeTimestamp)
 {
     if (inScope)
         Console.Write("Sending scope change to true in Monster\n");
     else
         Console.Write("Sending scope change to false in Monster\n");
     // Up to you to write this.  If you write nothing, the system will treat that as if you wanted to cancel the scope change
     outBitStream.Write(inScope);
     return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
 }
示例#49
0
        public ReplicaReturnResult SendScopeChange(bool inScope, BitStream outBitStream, uint currentTime, SystemAddress systemAddress, ref bool includeTimestamp)
        {
            if (inScope)
                Console.Write("Sending scope change to true in Player\n");
            else
                Console.Write("Sending scope change to false in Player\n");

            outBitStream.Write(inScope);
            return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
        }
示例#50
0
 static ReplicaReturnResult ReceiveDownloadCompleteCB(BitStream inBitStream, SystemAddress senderId, ReplicaManagerExt caller, IntPtr userData)
 {
     if (!isServer)
         Console.Write("Object downloads complete\n");
     return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
 }
 public ReplicaReturnResult SendScopeChange(bool inScope, BitStream outBitStream, uint currentTime, SystemAddress systemAddress, ref bool includeTimestamp)
 {
     return ReplicaReturnResult.REPLICA_CANCEL_PROCESS;
 }
 public void RemoveRow(string tableName, string removePassword, uint rowId, SystemAddress systemAddress, bool broadcast)
 {
     RakNetPINVOKE.LightweightDatabaseClient_RemoveRow(swigCPtr, tableName, removePassword, rowId, SystemAddress.getCPtr(systemAddress), broadcast);
     if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve();
 }
 public ReplicaReturnResult SendConstruction(uint currentTime, SystemAddress systemAddress, SWIGTYPE_p_unsigned_int flags, BitStream outBitStream, ref bool includeTimestamp)
 {
     return ReplicaReturnResult.REPLICA_CANCEL_PROCESS;
 }
 public ReplicaReturnResult ReceiveScopeChange(BitStream inBitStream, SystemAddress systemAddress, uint timestamp)
 {
     return ReplicaReturnResult.REPLICA_CANCEL_PROCESS;
 }
 private void QueryTableHelper(string tableName, string queryPassword, string[] columnNamesSubset, byte numColumnSubset, RakNetListDatabaseFilter filter, byte numFilters, uint[] rowIds, byte numRowIDs, SystemAddress systemAddress, bool broadcast)
 {
     RakNetPINVOKE.LightweightDatabaseClient_QueryTableHelper(swigCPtr, tableName, queryPassword, columnNamesSubset, numColumnSubset, RakNetListDatabaseFilter.getCPtr(filter), numFilters, rowIds, numRowIDs, SystemAddress.getCPtr(systemAddress), broadcast);
     if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve();
 }
示例#56
0
 public virtual void OnAllServersBusy(SystemAddress proxyCoordinator, SystemAddress sourceAddress, SystemAddress targetAddress, RakNetGUID targetGuid, UDPProxyClient proxyClientPlugin)
 {
     RakNetPINVOKE.CSharp_RakNet_UDPProxyClientResultHandler_OnAllServersBusy(swigCPtr, SystemAddress.getCPtr(proxyCoordinator), SystemAddress.getCPtr(sourceAddress), SystemAddress.getCPtr(targetAddress), RakNetGUID.getCPtr(targetGuid), UDPProxyClient.getCPtr(proxyClientPlugin));
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#57
0
 static ReplicaReturnResult SendDownloadCompleteCB(BitStream inBitStream, uint timestamp, SystemAddress senderId, ReplicaManagerExt caller, IntPtr userData)
 {
     return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
 }
 public ReplicaReturnResult Serialize(ref bool sendTimestamp, BitStream outBitStream, uint lastSendTime, ref PacketPriority priority, ref PacketReliability reliability, uint currentTime, SystemAddress systemAddress, SWIGTYPE_p_unsigned_int flags)
 {
     return ReplicaReturnResult.REPLICA_CANCEL_PROCESS;
 }
示例#59
0
 public virtual void OnFilePush(string fileName, uint fileLengthBytes, uint offset, uint bytesBeingSent, bool done, SystemAddress targetSystem, ushort setId)
 {
     RakNetPINVOKE.FileListProgress_OnFilePush(swigCPtr, fileName, fileLengthBytes, offset, bytesBeingSent, done, SystemAddress.getCPtr(targetSystem), setId);
     if (RakNetPINVOKE.SWIGPendingException.Pending)
     {
         throw RakNetPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public ReplicaReturnResult Deserialize(BitStream inBitStream, uint timestamp, uint lastDeserializeTime, SystemAddress systemAddress)
 {
     return ReplicaReturnResult.REPLICA_CANCEL_PROCESS;
 }