ReadString() public method

public ReadString ( int len ) : string
len int
return string
        internal NetworkP2PHandoverInstance(NetBuffer buffer)
        {
            _networkView = null;

            position   = new Vector3(buffer.ReadFloat(), buffer.ReadFloat(), buffer.ReadFloat());
            rotation   = new Quaternion(buffer.ReadFloat(), buffer.ReadFloat(), buffer.ReadFloat(), buffer.ReadFloat());
            relativeTo = (NetworkP2PSpace)buffer.ReadByte();

            remoteViewID           = new NetworkViewID(buffer);
            group                  = new NetworkGroup(buffer);
            authFlags              = (NetworkAuthFlags)buffer.ReadByte();
            isInstantiatedRemotely = buffer.ReadBoolean();

            proxyPrefab  = buffer.ReadString();
            ownerPrefab  = buffer.ReadString();
            serverPrefab = buffer.ReadString();

            cellAuthPrefab  = buffer.ReadString();
            cellProxyPrefab = buffer.ReadString();

            uint initialSize = buffer.ReadVariableUInt32();

            _initialData = initialSize != 0 ? buffer.ReadBytes((int)initialSize) : new byte[0];

            uint handoverSize = buffer.ReadVariableUInt32();

            _handoverData = handoverSize != 0 ? buffer.ReadBytes((int)handoverSize) : new byte[0];

            _isInstantiatable = true;
            _networkP2P       = null;
        }
コード例 #2
0
ファイル: FileSync.cs プロジェクト: pdm1996/Fragsurf-2
        public void Read(NetBuffer buffer)
        {
            Files.Clear();
            SyncType = (FileSyncType)buffer.ReadByte();

            if (SyncType == FileSyncType.Manifest)
            {
                DownloadUrl = buffer.ReadString();
            }

            if (SyncType == FileSyncType.Manifest ||
                SyncType == FileSyncType.Request)
            {
                var fileCount = buffer.ReadInt32();
                for (int i = 0; i < fileCount; i++)
                {
                    var fi = new FSFileInfo();
                    fi.RelativePath = buffer.ReadString();
                    fi.WorkshopId   = buffer.ReadUInt64();

                    if (SyncType == FileSyncType.Manifest)
                    {
                        fi.Hash = buffer.ReadBytes(16);
                    }
                    Files.Add(fi);
                }
            }
        }
コード例 #3
0
 public void Deserialize(NetBuffer pPacketReader)
 {
     type    = pPacketReader.ReadByte();
     name    = pPacketReader.ReadString();
     channel = pPacketReader.ReadString();
     message = pPacketReader.ReadString();
 }
コード例 #4
0
 public override void Read(NetBuffer msg)
 {
     login         = msg.ReadString();
     email         = msg.ReadString();
     passwordHash  = msg.ReadString();
     promotionCode = msg.ReadString();
 }
コード例 #5
0
        public bool ReadExtraCargo(NetBuffer msg)
        {
            bool   changed = false;
            UInt32 count   = msg.ReadUInt32();

            if (ExtraCargo == null || count != ExtraCargo.Count)
            {
                changed = true;
            }
            Dictionary <ItemPrefab, int> extraCargo = new Dictionary <ItemPrefab, int>();

            for (int i = 0; i < count; i++)
            {
                string prefabIdentifier = msg.ReadString();
                string prefabName       = msg.ReadString();
                byte   amount           = msg.ReadByte();

                var itemPrefab = string.IsNullOrEmpty(prefabIdentifier) ?
                                 MapEntityPrefab.Find(prefabName, null, showErrorMessages: false) as ItemPrefab :
                                 MapEntityPrefab.Find(prefabName, prefabIdentifier, showErrorMessages: false) as ItemPrefab;
                if (itemPrefab != null && amount > 0)
                {
                    if (changed || !ExtraCargo.ContainsKey(itemPrefab) || ExtraCargo[itemPrefab] != amount)
                    {
                        changed = true;
                    }
                    extraCargo.Add(itemPrefab, amount);
                }
            }
            if (changed)
            {
                ExtraCargo = extraCargo;
            }
            return(changed);
        }
コード例 #6
0
 public void Read(NetBuffer buffer)
 {
     Scope          = (ChatScope)buffer.ReadByte();
     Message        = buffer.ReadString();
     Name           = buffer.ReadString();
     ClientIndex    = buffer.ReadInt32();
     SupporterLevel = buffer.ReadInt32();
 }
 internal PeerDataFilter(NetBuffer buffer)
 {
     peerType          = buffer.ReadString();
     peerName          = buffer.ReadString();
     passwordProtected = _ReadNullableBool(buffer);
     comment           = buffer.ReadString();
     platform          = buffer.ReadString();
 }
コード例 #8
0
        public void ClientRead(NetBuffer inc)
        {
            AllowSubVoting = inc.ReadBoolean();
            if (allowSubVoting)
            {
                UpdateVoteTexts(null, VoteType.Sub);
                int votableCount = inc.ReadByte();
                for (int i = 0; i < votableCount; i++)
                {
                    int              votes      = inc.ReadByte();
                    string           subName    = inc.ReadString();
                    List <Submarine> serversubs = new List <Submarine>();
                    foreach (GUIComponent item in GameMain.NetLobbyScreen?.SubList?.Content?.Children)
                    {
                        if (item.UserData != null && item.UserData is Submarine)
                        {
                            serversubs.Add(item.UserData as Submarine);
                        }
                    }
                    Submarine sub = serversubs.FirstOrDefault(sm => sm.Name == subName);
                    SetVoteText(GameMain.NetLobbyScreen.SubList, sub, votes);
                }
            }
            AllowModeVoting = inc.ReadBoolean();
            if (allowModeVoting)
            {
                UpdateVoteTexts(null, VoteType.Mode);
                int votableCount = inc.ReadByte();
                for (int i = 0; i < votableCount; i++)
                {
                    int            votes          = inc.ReadByte();
                    string         modeIdentifier = inc.ReadString();
                    GameModePreset mode           = GameModePreset.List.Find(m => m.Identifier == modeIdentifier);
                    SetVoteText(GameMain.NetLobbyScreen.ModeList, mode, votes);
                }
            }
            AllowEndVoting = inc.ReadBoolean();
            if (AllowEndVoting)
            {
                GameMain.NetworkMember.EndVoteCount = inc.ReadByte();
                GameMain.NetworkMember.EndVoteMax   = inc.ReadByte();
            }
            AllowVoteKick = inc.ReadBoolean();

            GameMain.NetworkMember.ConnectedClients.ForEach(c => c.SetVote(VoteType.StartRound, false));
            byte readyClientCount = inc.ReadByte();

            for (int i = 0; i < readyClientCount; i++)
            {
                byte clientID       = inc.ReadByte();
                var  matchingClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == clientID);
                matchingClient?.SetVote(VoteType.StartRound, true);
            }
            UpdateVoteTexts(GameMain.NetworkMember.ConnectedClients, VoteType.StartRound);

            inc.ReadPadBits();
        }
コード例 #9
0
 internal LocalPeerData(NetBuffer buffer)
 {
     peerType          = buffer.ReadString();
     peerName          = buffer.ReadString();
     passwordProtected = (buffer.ReadByte() == 1);
     comment           = buffer.ReadString();
     platform          = buffer.ReadString();
     timestamp         = DateTime.FromBinary(buffer.ReadInt64());
     internalEndpoint  = buffer.ReadEndPoint();
 }
コード例 #10
0
        void R_AddFeedItem(NetConnection server, NetBuffer data, ushort numArgs)
        {
            string left       = data.ReadString();
            string leftAssist = data.ReadString();
            Color  leftColor  = new Color(data.ReadByte(), data.ReadByte(), data.ReadByte());
            string middle     = data.ReadString();
            string right      = data.ReadString();
            Color  rightColor = new Color(data.ReadByte(), data.ReadByte(), data.ReadByte());

            hud.AddFeedItem(left, leftAssist, leftColor, "[ " + middle + " ]", right, rightColor);
        }
コード例 #11
0
        public static CharacterInfo ClientRead(string configPath, NetBuffer inc)
        {
            ushort infoID              = inc.ReadUInt16();
            string newName             = inc.ReadString();
            int    gender              = inc.ReadByte();
            int    race                = inc.ReadByte();
            int    headSpriteID        = inc.ReadByte();
            int    hairIndex           = inc.ReadByte();
            int    beardIndex          = inc.ReadByte();
            int    moustacheIndex      = inc.ReadByte();
            int    faceAttachmentIndex = inc.ReadByte();
            string ragdollFile         = inc.ReadString();

            string    jobIdentifier = inc.ReadString();
            JobPrefab jobPrefab     = null;
            Dictionary <string, float> skillLevels = new Dictionary <string, float>();

            if (!string.IsNullOrEmpty(jobIdentifier))
            {
                jobPrefab = JobPrefab.List.Find(jp => jp.Identifier == jobIdentifier);
                byte skillCount = inc.ReadByte();
                for (int i = 0; i < skillCount; i++)
                {
                    string skillIdentifier = inc.ReadString();
                    float  skillLevel      = inc.ReadSingle();
                    skillLevels.Add(skillIdentifier, skillLevel);
                }
            }

            // TODO: animations
            CharacterInfo ch = new CharacterInfo(configPath, newName, jobPrefab, ragdollFile)
            {
                ID = infoID,
            };

            ch.RecreateHead(headSpriteID, (Race)race, (Gender)gender, hairIndex, beardIndex, moustacheIndex, faceAttachmentIndex);
            if (ch.Job != null)
            {
                foreach (KeyValuePair <string, float> skill in skillLevels)
                {
                    Skill matchingSkill = ch.Job.Skills.Find(s => s.Identifier == skill.Key);
                    if (matchingSkill == null)
                    {
                        ch.Job.Skills.Add(new Skill(skill.Key, skill.Value));
                        continue;
                    }
                    matchingSkill.Level = skill.Value;
                }
                ch.Job.Skills.RemoveAll(s => !skillLevels.ContainsKey(s.Identifier));
            }
            return(ch);
        }
コード例 #12
0
ファイル: Server.cs プロジェクト: KoalaDack/SteamDramaBot
        /**
         * The thread is now stuck in a while loop, forever waiting for an escape keypress.
         **/
        public void consoleIdle(bool idle)
        {
            while (idle)
            {
                NetMessageType type;
                NetConnection  sender;
                while (server.ReadMessage(readBuffer, out type, out sender))
                {
                    /**
                     * You must now put your code in here that you want the server to idle with, for instance, here is where you would init the comment sending system
                     **/

                    switch (type)
                    {
                    case NetMessageType.DebugMessage:
                        Debug.PrintDebug(readBuffer.ReadString());
                        break;

                    case NetMessageType.ConnectionApproval:
                        Debug.PrintEvent(string.Format("Connection Approval from {0}: {1}", sender, readBuffer.ReadString()));
                        break;

                    case NetMessageType.ConnectionRejected:
                        Debug.PrintError(string.Format("Connection Rejected from {0}: {1}", sender, readBuffer.ReadString()));
                        break;

                    case NetMessageType.StatusChanged:
                        string statusMessage          = readBuffer.ReadString();
                        NetConnectionStatus newStatus = (NetConnectionStatus)readBuffer.ReadByte();
                        Debug.PrintEvent(string.Format("New status from {0} : {1} ( '{2}' )", sender, newStatus, statusMessage));
                        break;

                    case NetMessageType.Data:
                        string msg = readBuffer.ReadString();
                        decideCommand(msg, sender);
                        Debug.PrintEvent(string.Format("New message from {0}: {1}", sender, msg));
                        break;
                    }
                }

                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        idle = false;
                    }
                }
                Thread.Sleep(1);
            }
            server.Shutdown("Server has been exited by the admin.");
        }
コード例 #13
0
        public bool ServerAdminRead(NetBuffer incMsg, Client c)
        {
            if (!c.HasPermission(ClientPermissions.ManageSettings))
            {
                bool   enabled     = incMsg.ReadBoolean(); incMsg.ReadPadBits();
                UInt16 removeCount = incMsg.ReadUInt16();
                incMsg.Position += removeCount * 4 * 8;
                UInt16 addCount = incMsg.ReadUInt16();
                for (int i = 0; i < addCount; i++)
                {
                    incMsg.ReadString(); //skip name
                    incMsg.ReadString(); //skip ip
                }
                return(false);
            }
            else
            {
                bool prevEnabled = Enabled;
                bool enabled     = incMsg.ReadBoolean(); incMsg.ReadPadBits();
                Enabled = enabled;

                UInt16 removeCount = incMsg.ReadUInt16();
                for (int i = 0; i < removeCount; i++)
                {
                    UInt16            id = incMsg.ReadUInt16();
                    WhiteListedPlayer whitelistedPlayer = whitelistedPlayers.Find(p => p.UniqueIdentifier == id);
                    if (whitelistedPlayer != null)
                    {
                        GameServer.Log(c.Name + " removed " + whitelistedPlayer.Name + " from whitelist (" + whitelistedPlayer.IP + ")", ServerLog.MessageType.ConsoleUsage);
                        RemoveFromWhiteList(whitelistedPlayer);
                    }
                }

                UInt16 addCount = incMsg.ReadUInt16();
                for (int i = 0; i < addCount; i++)
                {
                    string name = incMsg.ReadString();
                    string ip   = incMsg.ReadString();

                    GameServer.Log(c.Name + " added " + name + " to whitelist (" + ip + ")", ServerLog.MessageType.ConsoleUsage);
                    AddToWhiteList(name, ip);
                }

                bool changed = removeCount > 0 || addCount > 0 || prevEnabled != enabled;
                if (changed)
                {
                    Save();
                }
                return(changed);
            }
        }
コード例 #14
0
        public void Read(NetBuffer buffer)
        {
            GameVersion = buffer.ReadString();
            DisplayName = buffer.ReadString();
            Password    = buffer.ReadString();
            SteamID     = buffer.ReadUInt64();

            var len = buffer.ReadInt32();

            if (len > 0)
            {
                TicketData = buffer.ReadBytes(len);
            }
        }
コード例 #15
0
ファイル: MapItem.cs プロジェクト: limocute/Lunar-Engine
        public void Unpack(NetBuffer netBuffer, Layer layer)
        {
            var position = new Vector2(netBuffer.ReadFloat(), netBuffer.ReadFloat());

            _name = netBuffer.ReadString();

            var textureName = netBuffer.ReadString();

            _sprite = new Sprite(Client.ServiceLocator.Get <ContentManagerService>()
                                 .ContentManager.LoadTexture2D(Constants.FILEPATH_GFX + "/Items/" + textureName));

            _sprite.Transform.Position   = position;
            _sprite.Transform.LayerDepth = layer.ZIndex + .001f; // the .001f makes it so that the item spawns above the map layer, but just below actors
        }
コード例 #16
0
ファイル: CharacterInfo.cs プロジェクト: juanjp600/Barotrauma
        public static CharacterInfo ClientRead(string configPath, NetBuffer inc)
        {
            ushort infoID              = inc.ReadUInt16();
            string newName             = inc.ReadString();
            int    gender              = inc.ReadByte();
            int    race                = inc.ReadByte();
            int    headSpriteID        = inc.ReadByte();
            int    hairIndex           = inc.ReadByte();
            int    beardIndex          = inc.ReadByte();
            int    moustacheIndex      = inc.ReadByte();
            int    faceAttachmentIndex = inc.ReadByte();
            string ragdollFile         = inc.ReadString();

            string    jobIdentifier = inc.ReadString();
            JobPrefab jobPrefab     = null;
            Dictionary <string, float> skillLevels = new Dictionary <string, float>();

            if (!string.IsNullOrEmpty(jobIdentifier))
            {
                jobPrefab = JobPrefab.List.Find(jp => jp.Identifier == jobIdentifier);
                for (int i = 0; i < jobPrefab.Skills.Count; i++)
                {
                    float skillLevel = inc.ReadSingle();
                    skillLevels.Add(jobPrefab.Skills[i].Identifier, skillLevel);
                }
            }

            // TODO: animations
            CharacterInfo ch = new CharacterInfo(configPath, newName, jobPrefab, ragdollFile)
            {
                ID = infoID,
            };

            ch.RecreateHead(headSpriteID, (Race)race, (Gender)gender, hairIndex, beardIndex, moustacheIndex, faceAttachmentIndex);
            System.Diagnostics.Debug.Assert(skillLevels.Count == ch.Job.Skills.Count);
            if (ch.Job != null)
            {
                foreach (KeyValuePair <string, float> skill in skillLevels)
                {
                    Skill matchingSkill = ch.Job.Skills.Find(s => s.Identifier == skill.Key);
                    if (matchingSkill == null)
                    {
                        DebugConsole.ThrowError("Skill \"" + skill.Key + "\" not found in character \"" + newName + "\"");
                        continue;
                    }
                    matchingSkill.Level = skill.Value;
                }
            }
            return(ch);
        }
コード例 #17
0
 public void Read(NetBuffer im)
 {
     PluginName = im.ReadString();
     MethodName = im.ReadString();
     RspType    = im.ReadByte();
     if (RspType == StringDataType)
     {
         StringCommandRsp = im.ReadString();
     }
     else if (RspType == BinaryDataType)
     {
         int l = im.ReadInt32();
         BinaryCommandRsp = im.ReadBytes(l);
     }
 }
コード例 #18
0
        private void OnUnconnectedDataReceived(IPEndPoint endpoint, NetBuffer incomingData)
        {
            if (endpoint.Equals(_natFacilitatorEndpoint))
            {
                var messageType = (NatFacilitatorMessageType)incomingData.ReadByte();
                switch (messageType)
                {
                case NatFacilitatorMessageType.HostNotRegistered:
                    // Handle host not registered response
                    if (OnNatPunchFailure != null)
                    {
                        var punchId = new NatPunchId(incomingData.ReadString());
                        OnNatPunchFailure(punchId, endpoint);
                    }
                    break;

                case NatFacilitatorMessageType.PeerRegistrationSuccess:
                    if (_isRegistrationRunning)
                    {
                        _externalEndpoint.SetResult(incomingData.ReadIPEndPoint());
                    }
                    break;

                default:
                    // Skip this message
                    break;
                }
            }
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: sampad1370/lidgren-network
        static void OnAppIdle(object sender, EventArgs e)
        {
            while (NativeMethods.AppStillIdle)
            {
                NetMessageType type;
                if (m_client.ReadMessage(m_readBuffer, out type))
                {
                    switch (type)
                    {
                    case NetMessageType.ServerDiscovered:
                        IPEndPoint ep = m_readBuffer.ReadIPEndPoint();
                        m_client.Connect(ep);
                        break;

                    case NetMessageType.Receipt:
                        NativeMethods.AppendText(m_mainForm.richTextBox1, "Got receipt for packet sized " + m_readBuffer.ReadInt32());
                        if (m_client.Status == NetConnectionStatus.Connected)
                        {
                            m_nextSize *= 2;
                            if (m_nextSize > 1000000)
                            {
                                // 1 meg message is enough
                                NativeMethods.AppendText(m_mainForm.richTextBox1, "Done");
                                m_client.Disconnect("Done");
                                return;
                            }
                            SendPacket();
                        }
                        break;

                    case NetMessageType.VerboseDebugMessage:
                    case NetMessageType.DebugMessage:
                    case NetMessageType.BadMessageReceived:
                        NativeMethods.AppendText(m_mainForm.richTextBox1, m_readBuffer.ReadString());
                        break;

                    case NetMessageType.StatusChanged:
                        if (m_client.Status == NetConnectionStatus.Connected)
                        {
                            m_nextSize = 8;
                            SendPacket();
                        }
                        break;
                    }
                }

                if (m_client != null && m_client.ServerConnection != null)
                {
                    m_mainForm.Text = m_client.ServerConnection.Statistics.CurrentlyUnsentMessagesCount + " unsent messages";
                }

                if (NetTime.Now > s_nextDisplay)
                {
                    m_mainForm.label1.Text = m_client.GetStatisticsString(m_client.ServerConnection);
                    s_nextDisplay          = NetTime.Now + 0.2;            // five times per second
                }

                System.Threading.Thread.Sleep(1);
            }
        }
        public NetworkP2PMessage(NetBuffer buffer, NetConnection connection, NetChannel channel)
        {
            flags = 0;

            // read header from stream:

            var headerFlags = (HeaderFlags)buffer.ReadByte();

            internCode = (InternalCode)(headerFlags & HeaderFlags.InternalCode);
            isTypeSafe = ((headerFlags & HeaderFlags.IsTypeSafe) == HeaderFlags.IsTypeSafe);
            isReliable = ((int)channel & (int)NetChannel.ReliableUnordered) == (int)NetChannel.ReliableUnordered;

            if (!isInternal)
            {
                name = buffer.ReadString();
            }
            else
            {
                name = String.Empty;
            }

            stream          = new BitStream(buffer, isTypeSafe);
            this.connection = connection;
            this.channel    = channel;
        }
コード例 #21
0
        public bool ReadExtraCargo(NetBuffer msg)
        {
            bool   changed = false;
            UInt32 count   = msg.ReadUInt32();

            if (ExtraCargo == null || count != ExtraCargo.Count)
            {
                changed = true;
            }
            Dictionary <ItemPrefab, int> extraCargo = new Dictionary <ItemPrefab, int>();

            for (int i = 0; i < count; i++)
            {
                string     prefabName = msg.ReadString();
                byte       amount     = msg.ReadByte();
                ItemPrefab ip         = MapEntityPrefab.List.Find(p => p is ItemPrefab && p.Name.Equals(prefabName, StringComparison.InvariantCulture)) as ItemPrefab;
                if (ip != null && amount > 0)
                {
                    if (changed || !ExtraCargo.ContainsKey(ip) || ExtraCargo[ip] != amount)
                    {
                        changed = true;
                    }
                    extraCargo.Add(ip, amount);
                }
            }
            if (changed)
            {
                ExtraCargo = extraCargo;
            }
            return(changed);
        }
コード例 #22
0
        public void Unpack(NetBuffer netBuffer)
        {
            Client.ServiceLocator.GetService <LightManagerService>().Component.Lights.Clear();

            this.Dark = netBuffer.ReadBoolean();

            if (this.Dark)
            {
                Client.ServiceLocator.GetService <LightManagerService>().Component.AmbientColor = new Color(100, 100, 100, 20);
            }
            else
            {
                Client.ServiceLocator.GetService <LightManagerService>().Component.AmbientColor = Color.White;
            }

            int layerCount = netBuffer.ReadInt32();

            for (int i = 0; i < layerCount; i++)
            {
                string layerName = netBuffer.ReadString();
                int    lIndex    = netBuffer.ReadInt32();
                var    layer     = new Layer(this.Dimensions, lIndex, layerName);
                layer.Unpack(netBuffer);
                _layers.Add(layerName, layer);
            }
        }
コード例 #23
0
ファイル: ZoneProtocol.cs プロジェクト: massdriver/Multiverse
 public override void Read(NetBuffer msg)
 {
     worldZoneId     = msg.ReadUInt64();
     sceneBuildIndex = msg.ReadInt32();
     ip   = msg.ReadString();
     port = msg.ReadInt32();
 }
コード例 #24
0
        public void Read(NetBuffer im)
        {
            MetaData = im.ReadString();
            int l = im.ReadInt32();

            Data = im.ReadBytes(l);
        }
コード例 #25
0
 public void Deserialize(NetBuffer pPacketReader)
 {
     name     = pPacketReader.ReadString();
     subspace = pPacketReader.ReadInt32();
     clock    = pPacketReader.ReadDouble();
     unk      = pPacketReader.ReadBool();
 }
コード例 #26
0
ファイル: Client.cs プロジェクト: juanjp600/Barotrauma
        public static void ReadPermissions(NetBuffer inc, out ClientPermissions permissions, out List <DebugConsole.Command> permittedCommands)
        {
            UInt16 permissionsInt = inc.ReadUInt16();

            permissions       = ClientPermissions.None;
            permittedCommands = new List <DebugConsole.Command>();
            try
            {
                permissions = (ClientPermissions)permissionsInt;
            }
            catch (InvalidCastException)
            {
                return;
            }
            if (permissions.HasFlag(ClientPermissions.ConsoleCommands))
            {
                UInt16 commandCount = inc.ReadUInt16();
                for (int i = 0; i < commandCount; i++)
                {
                    string commandName    = inc.ReadString();
                    var    consoleCommand = DebugConsole.Commands.Find(c => c.names.Contains(commandName));
                    if (consoleCommand != null)
                    {
                        permittedCommands.Add(consoleCommand);
                    }
                }
            }
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: sampad1370/lidgren-network
        private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
        {
            switch (type)
            {
            case NetMessageType.DebugMessage:
                Console.WriteLine(buffer.ReadString());
                break;

            case NetMessageType.StatusChanged:
                NetConnectionStatus status = source.Status;
                if (status == NetConnectionStatus.Connected)
                {
                    source.Tag = ImageClientStatus.JustConnected;
                    s_nextPixelToSend[source] = 0;
                }
                else if (status == NetConnectionStatus.Disconnected)
                {
                    if (s_nextPixelToSend.ContainsKey(source))
                    {
                        s_nextPixelToSend.Remove(source);
                    }
                }
                break;

            case NetMessageType.Receipt:
                source.Tag = ImageClientStatus.Running;
                break;

            default:
                // unhandled
                break;
            }
        }
コード例 #28
0
ファイル: FileChunk.cs プロジェクト: pdm1996/Fragsurf-2
 public void Read(NetBuffer buffer)
 {
     File        = buffer.ReadString().ToLower();
     TotalLength = buffer.ReadInt64();
     ChunkLength = buffer.ReadInt32();
     Data        = buffer.ReadBytes(ChunkLength);
     Temporary   = buffer.ReadBoolean();
 }
コード例 #29
0
ファイル: CustomPacket.cs プロジェクト: pdm1996/Fragsurf-2
        public void Read(NetBuffer buffer)
        {
            DataEntries.Clear();

            Label = buffer.ReadString();
            byte entryCount = buffer.ReadByte();

            for (int i = 0; i < entryCount; i++)
            {
                var entry = new DataEntry();
                entry.Type = (DataType)buffer.ReadByte();
                switch (entry.Type)
                {
                case DataType.Bool:
                    entry.BoolValue = buffer.ReadBoolean();
                    break;

                case DataType.Int:
                    entry.IntValue = buffer.ReadInt32();
                    break;

                case DataType.Float:
                    entry.FloatValue = buffer.ReadSingle();
                    break;

                case DataType.Byte:
                    entry.ByteValue = buffer.ReadByte();
                    break;

                case DataType.String:
                    entry.StringValue = buffer.ReadString();
                    break;

                case DataType.Vector3:
                    entry.Vector3Value = buffer.ReadVector3();
                    break;

                case DataType.Bytes:
                    var byteCount = buffer.ReadInt32();
                    entry.BytesValue = buffer.ReadBytes(byteCount);
                    break;
                }

                DataEntries.Add(entry);
            }
        }
コード例 #30
0
        private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
        {
            switch (type)
            {
            case NetMessageType.DebugMessage:
                WriteToConsole(buffer.ReadString());
                break;

            case NetMessageType.StatusChanged:
                string statusMessage          = buffer.ReadString();
                NetConnectionStatus newStatus = (NetConnectionStatus)buffer.ReadByte();

                WriteToConsole("New status: " + newStatus + " (" + statusMessage + ")");
                UpdateStatisticsDisplay(source);
                break;

            case NetMessageType.Data:
                //System.IO.File.AppendAllText("C:\\receivedpackets.txt", s_userMessagesReceived.ToString() + ": " + msg.ReadString() + " (" + msg.m_sequenceNumber + ")" + Environment.NewLine);
                s_userMessagesReceived++;

                // simulate some processing of the message here
                for (int i = 0; i < buffer.LengthBytes - 2; i++)
                {
                    buffer.ReadByte();
                }

                // check checksum
                ushort checksum = NetChecksum.Adler16(buffer.Data, 0, buffer.LengthBytes - 2);
                ushort given    = buffer.ReadUInt16();
                if (checksum != given)
                {
                    WriteToConsole("Wrong checksum! Expected " + checksum + " found given " + given);
                }

                double b = s_userMessagesReceived;
                for (int i = 0; i < 1000; i++)
                {
                    b += Math.Sqrt((double)i) / Math.Sin(s_tmp);
                }
                s_tmp += b / 10000.0;
                break;

            default:
                break;
            }
        }