當前位置: 首頁>>代碼示例>>C#>>正文


C# Position.Set方法代碼示例

本文整理匯總了C#中fCraft.Position.Set方法的典型用法代碼示例。如果您正苦於以下問題:C# Position.Set方法的具體用法?C# Position.Set怎麽用?C# Position.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fCraft.Position的用法示例。


在下文中一共展示了Position.Set方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IoLoop

        void IoLoop() {
            short x, y, h;
            byte mode, type, opcode;
            Packet packet;

            int pollInterval = 200;
            int pollCounter = 0;
            int packetsSent = 0;

            try {
                LoginSequence();
                canSend = true;

                while( !canDispose ) {
                    Thread.Sleep( 1 );
                    packetsSent = 0;

                    // detect player disconnect
                    if( pollCounter > pollInterval ) {
                        if( !client.Connected ||
                            (client.Client.Poll( 1000, SelectMode.SelectRead ) && client.Client.Available == 0) ) {
                            world.log.Log( "Session.IoLoop: Lost connection to {0}.", LogType.Debug, player.name );
                            return;
                        }
                        pollCounter = 0;
                    }
                    pollCounter++;

                    // send priority output to player
                    while( canSend && priorityOutputQueue.Count > 0 && packetsSent < Server.maxSessionPacketsPerTick ) {
                        lock( priorityQueueLock ) {
                            packet = priorityOutputQueue.Dequeue();
                        }
                        writer.Write( packet.data );
                        packetsSent++;
                        if( packet.data[0] == (byte)OutputCodes.Disconnect ) {
                            world.log.Log( "Session.IoLoop: Kick packet delivered to {0}.", LogType.Debug, player.name );
                            return;
                        }
                    }

                    // send output to player
                    while( canSend && outputQueue.Count > 0 && packetsSent < Server.maxSessionPacketsPerTick ) {
                        lock( queueLock ) {
                            packet = outputQueue.Dequeue();
                        }
                        writer.Write( packet.data );
                        packetsSent++;
                        if( packet.data[0] == (byte)OutputCodes.Disconnect ) {
                            writer.Flush();
                            world.log.Log( "Session.IoLoop: Kick packet delivered to {0}.", LogType.Debug, player.name );
                            return;
                        }
                    }

                    // get input from player
                    while( canReceive && client.GetStream().DataAvailable ) {
                        opcode = reader.ReadByte();
                        switch( (InputCodes)opcode ) {

                            // Message
                            case InputCodes.Message:
                                reader.ReadByte();
                                string message = ReadString();
                                if( Player.CheckForIllegalChars( message ) ) {
                                    world.log.Log( "Player.ParseMessage: {0} attempted to write illegal characters in chat and was kicked.",
                                                LogType.SuspiciousActivity,
                                                player.name );
                                    KickNow( "Illegal characters in chat." );
                                    return;
                                } else {
                                    player.ParseMessage( message, false );
                                }
                                break;

                            // Player movement
                            case InputCodes.MoveRotate:
                                reader.ReadByte();
                                Position newPos = new Position();
                                newPos.x = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                newPos.h = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                newPos.y = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                newPos.r = reader.ReadByte();
                                newPos.l = reader.ReadByte();

                                if( newPos.h < 0 || newPos.x < -32 || newPos.x >= world.map.widthX * 32+32 || newPos.y < -32 || newPos.y > world.map.widthY * 32+32 ) {
                                    world.log.Log( player.name + " was kicked for moving out of map boundaries.", LogType.SuspiciousActivity );
                                    world.SendToAll( player.name + " was kicked for moving out of map boundaries.", null );
                                    KickNow( "Hacking detected: out of map boundaries." );
                                    return;
                                }

                                Position delta = new Position(), oldPos = player.pos;
                                bool posChanged, rotChanged;

                                if( !player.isHidden ) {
                                    delta.Set( newPos.x - oldPos.x, newPos.y - oldPos.y, newPos.h - oldPos.h, newPos.r, newPos.l );
                                    posChanged = delta.x != 0 || delta.y != 0 || delta.h != 0;
                                    rotChanged = newPos.r != oldPos.r || newPos.l != oldPos.l;

//.........這裏部分代碼省略.........
開發者ID:fragmer,項目名稱:fCraft,代碼行數:101,代碼來源:Session.cs


注:本文中的fCraft.Position.Set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。