cs_elbot.TCPWrapper.Send C# (CSharp) Method

Send() public method

public Send ( byte data ) : int
data byte
return int
        public int Send(byte[] data)
        {
            //need to put a check in here for pms with no username...

            int result;
            if (data[0]==0x02)
            {
                // Check if we send a PM from console
                string Message = System.Text.ASCIIEncoding.ASCII.GetString(data, 3, data.Length-3);
                string[] PMArray = Message.Split(' ');
                if (Message.StartsWith("Console:\\>"))
                {
                    TheLogger.Log(Message);
                    return data.Length;
                }
                else
                {
                    this.PMCounter++;
                    if (this.PMCounter>5)
                    {
                        // Do a sleep after sending 7 Sends
                        // Do a sleep after sending 5 Sends
                        System.Threading.Thread.Sleep(500);
                        this.PMCounter = 0;
                    }
                }
                if (data.Length > 159)
                {
                    byte[] check = new byte[159];
                    Array.Copy(data, check, 159);
                    result = TheTCPClient.Send(check);
                    if (result > 0)
                    {
                        OnSentCommand(new SentCommandEventArgs(data));
                    }
                    return result;
                }
                else
                {
                    byte[] check = new byte[data.Length];
                    Array.Copy(data, check, data.Length);
                    result = TheTCPClient.Send(check);
                    if (result > 0)
                    {
                        OnSentCommand(new SentCommandEventArgs(data));
                    }
                    return result;
                }
            }

            result = TheTCPClient.Send(data);
            if (result>0)
            {
                OnSentCommand(new SentCommandEventArgs(data));
            }
            return result;
        }

Usage Example

Example #1
0
 public void requestInventory()
 {
     Console.WriteLine("inventory requested: " + inventoryRequested);
     if (!inventoryRequested)
     {
         inventoryRequested = true;
         TheTCPWrapper.Send(CommandCreator.SEND_MY_INVENTORY());
     }
 }