当前位置: 首页>>代码示例>>C#>>正文


C# BinaryWriter.WriteBE方法代码示例

本文整理汇总了C#中System.IO.BinaryWriter.WriteBE方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.WriteBE方法的具体用法?C# BinaryWriter.WriteBE怎么用?C# BinaryWriter.WriteBE使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryWriter的用法示例。


在下文中一共展示了BinaryWriter.WriteBE方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Pack

        public byte[] Pack()
        {
            using (var ms = new MemoryStream())
            {
                using (var bw = new BinaryWriter(ms))
                {
                    bw.WriteBE((uint)0x4B616D65); // 'Kamek\0\0\1'
                    bw.WriteBE((uint)0x6B000001);
                    bw.WriteBE((uint)_bssSize);
                    bw.WriteBE((uint)_codeBlob.Length);

                    bw.Write(_codeBlob);
                }

                return ms.ToArray();
            }
        }
开发者ID:Treeki,项目名称:Kamek,代码行数:17,代码来源:KamekFile.cs

示例2: doProcess

        public override bool doProcess(string[] args)
        {
            if (!hasPermission()) { permissionError(); return false; }

            this.client.sendCommandMessage("Teleporting to your home planet.");

            MemoryStream packetWarp = new MemoryStream();
            BinaryWriter packetWrite = new BinaryWriter(packetWarp);

            uint warp = (uint)WarpType.WarpToHomePlanet;
            string sector = "";
            int x = 0;
            int y = 0;
            int z = 0;
            int planet = 0;
            int satellite = 0;
            string player = "";
            packetWrite.WriteBE(warp);
            packetWrite.WriteStarString(sector);
            packetWrite.WriteBE(x);
            packetWrite.WriteBE(y);
            packetWrite.WriteBE(z);
            packetWrite.WriteBE(planet);
            packetWrite.WriteBE(satellite);
            packetWrite.WriteStarString(player);
            client.sendServerPacket(Packet.WarpCommand, packetWarp.ToArray());

            return true;
        }
开发者ID:Gremlin13,项目名称:StarryboundServer,代码行数:29,代码来源:Home.cs

示例3: doProcess

        public override bool doProcess(string[] args)
        {
            if (!hasPermission()) { permissionError(); return false; }

            string player = string.Join(" ", args).Trim();

            uint warp;

            if (player == null || player.Length < 1)
            {
                this.client.sendCommandMessage("Teleporting to your ship.");

                player = "";
                warp = (uint)WarpType.WarpToOwnShip;
            }
            else
            {
                PlayerData targetPlayer = StarryboundServer.clients[player].playerData;
                if (!hasPermission(true)) { permissionError(2); return false; }
                if (!this.player.canAccessShip(targetPlayer))
                {
                    this.client.sendCommandMessage("You cannot access this player's ship due to their ship's access settings.");
                    return false;
                }
                this.client.sendCommandMessage("Teleporting to " + player + " ship!");

                warp = (uint)WarpType.WarpToPlayerShip;
            }

            MemoryStream packetWarp = new MemoryStream();
            BinaryWriter packetWrite = new BinaryWriter(packetWarp);

            string sector = "";
            int x = 0;
            int y = 0;
            int z = 0;
            int planet = 0;
            int satellite = 0;
            packetWrite.WriteBE(warp);
            packetWrite.WriteStarString(sector);
            packetWrite.WriteBE(x);
            packetWrite.WriteBE(y);
            packetWrite.WriteBE(z);
            packetWrite.WriteBE(planet);
            packetWrite.WriteBE(satellite);
            packetWrite.WriteStarString(player);
            client.sendServerPacket(Packet.WarpCommand, packetWarp.ToArray());

            return true;
        }
开发者ID:Zallist,项目名称:StarryboundServer,代码行数:50,代码来源:Ship.cs

示例4: doProcess

        public override bool doProcess(string[] args)
        {
            if (!hasPermission()) { permissionError(); return false; }

            this.client.sendCommandMessage("Teleporting to orbited planet.");

            MemoryStream packetWarp = new MemoryStream();
            BinaryWriter packetWrite = new BinaryWriter(packetWarp);

            uint warp = (uint)WarpType.WarpToOrbitedPlanet;
            string player = "";
            packetWrite.WriteBE(warp);
            packetWrite.Write(new WorldCoordinate());
            packetWrite.WriteStarString(player);
            client.sendServerPacket(Packet.WarpCommand, packetWarp.ToArray());

            return true;
        }
开发者ID:k0rd,项目名称:StarryboundServer,代码行数:18,代码来源:Planet.cs

示例5: doProcess

        public override bool doProcess(string[] args)
        {
            if (!hasPermission()) { permissionError(); return false; }

            if (StarryboundServer.serverConfig.useDefaultWorldCoordinate && StarryboundServer.spawnPlanet != null)
            {
                MemoryStream packetWarp = new MemoryStream();
                BinaryWriter packetWrite = new BinaryWriter(packetWarp);

                packetWrite.WriteBE((uint)WarpType.MoveShip);
                packetWrite.Write(StarryboundServer.spawnPlanet);
                packetWrite.WriteStarString("");
                client.sendServerPacket(Packet.WarpCommand, packetWarp.ToArray());
                this.client.sendCommandMessage("Teleporting your ship to the spawn planet.");
                return true;
            }
            this.client.sendCommandMessage("Spawn planet not enabled.");
            return false;
        }
开发者ID:k0rd,项目名称:StarryboundServer,代码行数:19,代码来源:Spawn.cs

示例6: doProcess

        public override bool doProcess(string[] args)
        {
            if (!hasPermission()) { permissionError(); return false; }

            string player = string.Join(" ", args).Trim();

            WorldCoordinate loc = this.player.loc;

            if (player == null || player.Length < 1)
            {
                showHelpText();
                return false;
            }
            else
            {
                Client target = StarryboundServer.getClient(player);
                if (target != null)
                {
                    loc = target.playerData.loc;
                    if (loc == null)
                    {
                        this.client.sendCommandMessage("Unable to find an exact location for " + player + ".");
                        return false;
                    }
                    this.client.sendCommandMessage("Warping ship to " + player + " [" + loc.ToString() + "]");
                }
                else
                {
                    this.client.sendCommandMessage("Player '" + player + "' not found.");
                    return false;
                }
            }

            MemoryStream packetWarp = new MemoryStream();
            BinaryWriter packetWrite = new BinaryWriter(packetWarp);

            packetWrite.WriteBE((uint)WarpType.MoveShip);
            packetWrite.Write(loc);
            packetWrite.WriteStarString("");
            client.sendServerPacket(Packet.WarpCommand, packetWarp.ToArray());
            return true;
        }
开发者ID:k0rd,项目名称:StarryboundServer,代码行数:42,代码来源:WarpShip.cs

示例7: onSend

        public override void onSend()
        {
            if (tmpArray.Count < 5) return;

            MemoryStream packet = new MemoryStream();
            BinaryWriter packetWrite = new BinaryWriter(packet);

            ChatReceiveContext sContext = (ChatReceiveContext)tmpArray["context"];
            string sWorld = (string)tmpArray["world"];
            uint sClientID = (uint)tmpArray["entityID"]; // Player entity ID
            string sName = (string)tmpArray["name"]; // Name
            string sMessage = (string)tmpArray["message"]; // Message

            packetWrite.Write((byte)sContext);
            packetWrite.WriteStarString(sWorld);
            packetWrite.WriteBE(sClientID);
            packetWrite.WriteStarString(sName);
            packetWrite.WriteStarString(sMessage);
            this.client.sendClientPacket(Packet.ChatReceive, packet.ToArray());
        }
开发者ID:noxturno,项目名称:StarryboundServer,代码行数:20,代码来源:Packet11ChatSend.cs

示例8: Write

        private void Write(ShapefileHeader header, BinaryWriter stream, int fileLength)
        {
            stream.BaseStream.Seek(0, SeekOrigin.Begin);

            stream.WriteBE(9994);
            stream.WriteBE(0);
            stream.WriteBE(0);
            stream.WriteBE(0);
            stream.WriteBE(0);
            stream.WriteBE(0);
            stream.WriteBE(fileLength);
            stream.Write(1000);
            stream.Write((int)header.ShapeType);
            stream.Write(header.Bounds.Minimum.X);
            stream.Write(header.Bounds.Minimum.Y);
            stream.Write(header.Bounds.Maximum.X);
            stream.Write(header.Bounds.Maximum.Y);
        }
开发者ID:interworks,项目名称:FastShapefile,代码行数:18,代码来源:ShapefileWriter.cs

示例9: run


//.........这里部分代码省略.........
                                    this.client.rejectPreConnected("Violated PendingAuthentication protocol state with " + packetID);
                                    return;
                                }
                                else if (curState == ClientState.PendingConnectResponse)
                                {
                                    int startTime = Utils.getTimestamp();
                                    while (true)
                                    {
                                        if (this.client.state == ClientState.Connected) break;
                                        if (Utils.getTimestamp() > startTime + StarryboundServer.config.connectTimeout)
                                        {
                                            this.client.rejectPreConnected("Connection Failed: Server did not respond in time.");
                                            return;
                                        }
                                    }
                                }
                            }
                            #endregion

                            if (packetID == Packet.ChatSend)
                            {
                                returnData = new Packet11ChatSend(this.client, packetData, this.direction).onReceive();
                            }
                            else if (packetID == Packet.ClientConnect)
                            {
                                this.client.state = ClientState.PendingAuthentication;
                                returnData = new Packet7ClientConnect(this.client, packetData, this.direction).onReceive();
                                MemoryStream packet = new MemoryStream();
                                BinaryWriter packetWrite = new BinaryWriter(packet);

                                passwordSalt = Utils.GenerateSecureSalt();
                                packetWrite.WriteStarString("");
                                packetWrite.WriteStarString(passwordSalt);
                                packetWrite.WriteBE(StarryboundServer.config.passwordRounds);
                                this.client.sendClientPacket(Packet.HandshakeChallenge, packet.ToArray());
                            }
                            else if (packetID == Packet.HandshakeResponse)
                            {
                                string claimResponse = packetData.ReadStarString();
                                string passwordHash = packetData.ReadStarString();

                                string verifyHash = Utils.StarHashPassword(StarryboundServer.config.proxyPass, this.client.playerData.account + passwordSalt, StarryboundServer.config.passwordRounds);
                                if (passwordHash != verifyHash)
                                {
                                    this.client.rejectPreConnected("Your password was incorrect.");
                                    return;
                                }

                                this.client.state = ClientState.PendingConnectResponse;
                                returnData = false;
                            }
                            else if (packetID == Packet.WarpCommand)
                            {
                                WarpType cmd = (WarpType)packetData.ReadUInt32BE();
                                WorldCoordinate coord = packetData.ReadStarWorldCoordinate();
                                string player = packetData.ReadStarString();
                                if (cmd == WarpType.WarpToPlayerShip)
                                {
                                    Client target = StarryboundServer.getClient(player);
                                    if (target != null)
                                    {
                                        if (!this.client.playerData.canAccessShip(target.playerData))
                                        {
                                            this.client.sendChatMessage("^#5dc4f4;You cannot access this player's ship due to their ship access settings.");
                                            StarryboundServer.logDebug("ShipAccess", "Preventing " + this.client.playerData.name + " from accessing " + target.playerData.name + "'s ship.");
                                            MemoryStream packetWarp = new MemoryStream();
开发者ID:k0rd,项目名称:StarryboundServer,代码行数:67,代码来源:ForwardThread.cs

示例10: run


//.........这里部分代码省略.........
                            #region Protocol State Security
                            ClientState curState = this.mParent.clientState;
                            if (curState != ClientState.Connected)
                            {
                                if (curState == ClientState.PendingConnect && packetID != Packet.ClientConnect)
                                {
                                    this.mParent.forceDisconnect("Violated PendingConnect protocol state with " + packetID);
                                }
                                else if (curState == ClientState.PendingAuthentication && packetID != Packet.HandshakeResponse)
                                {
                                    this.mParent.forceDisconnect("Violated PendingAuthentication protocol state with " + packetID);
                                }
                                else if (curState == ClientState.PendingConnectResponse)
                                {
                                    this.mParent.forceDisconnect("Violated PendingConnectResponse protocol state with " + packetID);
                                }
                            }
                            #endregion

                            if (packetID == Packet.ChatSend)
                            {
                                returnData = new Packet11ChatSend(this.mParent, packetData, this.mDirection).onReceive();
                            }
                            else if (packetID == Packet.ClientConnect)
                            {
                                this.mParent.clientState = ClientState.PendingAuthentication;
                                returnData = new Packet7ClientConnect(this.mParent, packetData, this.mDirection).onReceive();
                                MemoryStream packet = new MemoryStream();
                                BinaryWriter packetWrite = new BinaryWriter(packet);

                                passwordSalt = Utils.GenerateSecureSalt();
                                packetWrite.WriteStarString("");
                                packetWrite.WriteStarString(passwordSalt);
                                packetWrite.WriteBE(StarryboundServer.config.passwordRounds);
                                this.mParent.sendClientPacket(Packet.HandshakeChallenge, packet.ToArray());
                            }
                            else if (packetID == Packet.HandshakeResponse)
                            {
                                string claimResponse = packetData.ReadStarString();
                                string passwordHash = packetData.ReadStarString();

                                string verifyHash = Utils.StarHashPassword(StarryboundServer.config.proxyPass, this.mParent.playerData.account + passwordSalt, StarryboundServer.config.passwordRounds);
                                if (passwordHash != verifyHash)
                                {
                                    this.mParent.rejectPreConnected("Your password was incorrect.");
                                }

                                this.mParent.clientState = ClientState.PendingConnectResponse;
                                returnData = false;
                            }
                            else if (packetID == Packet.WarpCommand)
                            {
                                uint warp = packetData.ReadUInt32BE();
                                WorldCoordinate coord = packetData.ReadStarWorldCoordinate();
                                string player = packetData.ReadStarString();
                                WarpType cmd = (WarpType)warp;
                                if (cmd == WarpType.WarpToHomePlanet)
                                {
                                    this.mParent.playerData.inPlayerShip = false;
                                }
                                else if (cmd == WarpType.WarpToOrbitedPlanet)
                                {
                                    this.mParent.playerData.inPlayerShip = false;
                                }
                                else if (cmd == WarpType.WarpToOwnShip)
                                {
开发者ID:Gremlin13,项目名称:StarryboundServer,代码行数:67,代码来源:ForwardThread.cs

示例11: run

        public void run()
        {
            try
            {
                this.cIn = new BinaryReader(this.cSocket.GetStream());
                this.cOut = new BinaryWriter(this.cSocket.GetStream());

                IPEndPoint ipep = (IPEndPoint)this.cSocket.Client.RemoteEndPoint;
                IPAddress ipa = ipep.Address;

                this.playerData.ip = ipep.Address.ToString();

                StarryboundServer.logInfo("[" + playerData.client + "] Accepting new connection.");

                sSocket = new TcpClient();
                sSocket.Connect(IPAddress.Loopback, StarryboundServer.config.serverPort);

                this.sIn = new BinaryReader(this.sSocket.GetStream());
                this.sOut = new BinaryWriter(this.sSocket.GetStream());

                if (!sSocket.Connected)
                {
                    MemoryStream packet = new MemoryStream();
                    BinaryWriter packetWrite = new BinaryWriter(packet);
                    packetWrite.WriteBE(StarryboundServer.ProtocolVersion);
                    this.sendClientPacket(Packet.ProtocolVersion, packet.ToArray());

                    rejectPreConnected("Starrybound server was unable to connect to the parent server.");
                    return;
                }

                // Forwarding for data from SERVER (sIn) to CLIENT (cOut)
                new Thread(new ThreadStart(new ForwardThread(this, this.sIn, this.cOut, Direction.Server).run)).Start();

                // Forwarding for data from CLIENT (cIn) to SERVER (sOut)
                new Thread(new ThreadStart(new ForwardThread(this, this.cIn, this.sOut, Direction.Client).run)).Start();
            }
            catch (Exception e)
            {
                MemoryStream packet = new MemoryStream();
                BinaryWriter packetWrite = new BinaryWriter(packet);
                packetWrite.WriteBE(StarryboundServer.ProtocolVersion);
                this.sendClientPacket(Packet.ProtocolVersion, packet.ToArray());
                rejectPreConnected("Starrybound server was unable to connect to the parent server.");
                StarryboundServer.logException("ClientThread Exception: " + e.Message);
            }
        }
开发者ID:Gremlin13,项目名称:StarryboundServer,代码行数:47,代码来源:ClientThread.cs

示例12: doProcess

        public override bool doProcess(string[] args)
        {
            if (!hasPermission()) { permissionError(); return false; }

            string player = string.Join(" ", args).Trim();

            uint warp;

            if (player == null || player.Length < 1)
            {
                this.client.sendCommandMessage("Teleporting to your ship.");

                player = "";
                warp = (uint)WarpType.WarpToOwnShip;
            }
            else
            {
                if (!hasPermission(true)) { permissionError(2); return false; }

                Client target = StarryboundServer.getClient(player);
                if (target != null)
                {
                    PlayerData targetPlayer = target.playerData;
                    if (!this.player.canAccessShip(targetPlayer))
                    {
                        this.client.sendCommandMessage("You cannot access this player's ship due to their ship's access settings.");
                        return false;
                    }
                    this.client.sendCommandMessage("Teleporting to " + player + " ship!");

                    warp = (uint)WarpType.WarpToPlayerShip;
                }
                else
                {
                    this.client.sendCommandMessage("Player '" + player + "' not found.");
                    return false;
                }
            }

            MemoryStream packetWarp = new MemoryStream();
            BinaryWriter packetWrite = new BinaryWriter(packetWarp);
            packetWrite.WriteBE(warp);
            packetWrite.Write(new WorldCoordinate());
            packetWrite.WriteStarString(player);
            client.sendServerPacket(Packet.WarpCommand, packetWarp.ToArray());

            return true;
        }
开发者ID:k0rd,项目名称:StarryboundServer,代码行数:48,代码来源:Ship.cs

示例13: run

        public void run()
        {
            try
            {
                this.cIn = new BinaryReader(this.cSocket.GetStream());
                this.cOut = new BinaryWriter(this.cSocket.GetStream());

                IPEndPoint ipep = (IPEndPoint)this.cSocket.Client.RemoteEndPoint;
                IPAddress ipa = ipep.Address;

                this.playerData.ip = ipep.Address.ToString();

                StarryboundServer.logInfo("[" + playerData.client + "] Accepting new connection.");

                if(StarryboundServer.serverState != ServerState.Running)
                {
                    MemoryStream packet = new MemoryStream();
                    BinaryWriter packetWrite = new BinaryWriter(packet);
                    packetWrite.WriteBE(StarryboundServer.ProtocolVersion);
                    this.sendClientPacket(Packet.ProtocolVersion, packet.ToArray());

                    rejectPreConnected("Connection Failed: The server is not ready yet.");
                    return;
                }

                sSocket = new TcpClient();
                IAsyncResult result = sSocket.BeginConnect(IPAddress.Loopback, StarryboundServer.config.serverPort, null, null);
                bool success = result.AsyncWaitHandle.WaitOne(3000, true);
                if (!success)
                {
                    StarryboundServer.failedConnections++;
                    if (StarryboundServer.failedConnections >= StarryboundServer.config.maxFailedConnections)
                    {
                        StarryboundServer.logFatal(StarryboundServer.failedConnections + " clients failed to connect in a row. Restarting...");
                        StarryboundServer.serverState = ServerState.Crashed;
                    }
                    MemoryStream packet = new MemoryStream();
                    BinaryWriter packetWrite = new BinaryWriter(packet);
                    packetWrite.WriteBE(StarryboundServer.ProtocolVersion);
                    this.sendClientPacket(Packet.ProtocolVersion, packet.ToArray());
                    rejectPreConnected("Connection Failed: Unable to connect to the parent server.");
                    return;
                }

                this.sIn = new BinaryReader(this.sSocket.GetStream());
                this.sOut = new BinaryWriter(this.sSocket.GetStream());

                // Forwarding for data from SERVER (sIn) to CLIENT (cOut)
                this.ServerForwarder = new Thread(new ThreadStart(new ForwardThread(this, this.sIn, this.cOut, Direction.Server).run));
                ServerForwarder.Start();

                // Forwarding for data from CLIENT (cIn) to SERVER (sOut)
                this.ClientForwarder = new Thread(new ThreadStart(new ForwardThread(this, this.cIn, this.sOut, Direction.Client).run));
                ClientForwarder.Start();

                StarryboundServer.failedConnections = 0;
            }
            catch (Exception e)
            {
                StarryboundServer.logException("ClientThread Exception: " + e.ToString());
                StarryboundServer.failedConnections++;
                MemoryStream packet = new MemoryStream();
                BinaryWriter packetWrite = new BinaryWriter(packet);
                packetWrite.WriteBE(StarryboundServer.ProtocolVersion);
                this.sendClientPacket(Packet.ProtocolVersion, packet.ToArray());
                rejectPreConnected("Connection Failed: A internal server error occurred (1)");
            }
        }
开发者ID:Zallist,项目名称:StarryboundServer,代码行数:68,代码来源:Client.cs


注:本文中的System.IO.BinaryWriter.WriteBE方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。