fastCopy() public static méthode

public static fastCopy ( byte source, byte destination, int length ) : void
source byte
destination byte
length int
Résultat void
Exemple #1
0
        private void finalReceiveFrom(IAsyncResult iar)
        {
            Socket   recvSocket = (Socket)iar.AsyncState;
            EndPoint Remote     = new IPEndPoint(IPAddress.Any, 0);
            int      msgLen     = 0;

            try
            {
                msgLen = recvSocket.EndReceiveFrom(iar, ref Remote);
            }catch (SocketException ex)
            {
            }
            finally
            {
                byte[] finalMessage = new byte[msgLen];
                ArrayUtils.fastCopy(buffer, finalMessage, msgLen);

                string key = Remote.ToString();


                // TODO CLIENT CHECK AND HANDLING
                lock (Clients.SyncRoot)
                {
                    WorldClient value;
                    if (Clients.ContainsKey(key))
                    {
                        value = Clients[key] as WorldClient;
                        Store.currentClient = Clients[key] as WorldClient;
                    }
                    else
                    {
                        objMan.PushClient(key); // Push first, then create it
                        value = new WorldClient(Remote, socket, key);
                        gameServerEntities.Add(objMan.GetAssignedObject(key));
                        value.playerData.setEntityId(WorldSocket.entityIdCounter++);

                        Clients.Add(key, value);
                    }
                    // Once one player enters, clean all
                    Store.currentClient = value; // BEFORE processing

                    value.processPacket(finalMessage);
                }
                // Listening for a new message
                EndPoint newClientEP = new IPEndPoint(IPAddress.Any, 0);
                try
                {
                    socket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref Remote, finalReceiveFrom, socket);
                }catch (Exception ex)
                {
                    // if we get exception - remove the client
                    // ToDo:
                    Store.currentClient.Alive = false;
                }
            }
        }
Exemple #2
0
        private byte[] parseCommand(byte[] command, int length)
        {
            byte[] temp = new byte[length];


            ArrayUtils.fastCopy(command, temp, length);           //saves time and so
            string response = "";

            string txtCommand  = StringUtils.charBytesToString(temp);
            bool   responseSet = false;

            //TODO: REMOVE CLIENT CONSOLE

            if (!responseSet)
            {
                return(StringUtils.stringToBytes("Unrecognized command: " + txtCommand));
            }

            return(StringUtils.stringToBytes(response));
        }