Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Pedroalves

Login c# usando sockets

Recommended Posts

não estou a conseguir enviar do cliente para servidor o username e password e retornar para cliente se o username e a password esta correcta

 

segue-se o codigo

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using TomShane.Neoforce.Central.Code;

namespace TomShane.Neoforce.Central.Code
{
    public class Server
    {
        //Singleton in case we need to access this object without a reference (call <Class_Name>.singleton)
        public static Server singleton;
        
        //Create an object of the Listener class.
        Listener listener;
        public Listener Listener
        {
            get { return listener; }
        }

        //Array of clients
        Client[] client;

        //number of connected clients
        int connectedClients = 0;

        //Writers and readers to manipulate data
        MemoryStream readStream;
        MemoryStream writeStream;
        BinaryReader reader;
        BinaryWriter writer;

        /// <summary>
        /// Create a new Server object
        /// </summary>
        /// <param name="port">The port you want to use</param>
        public Server(int port)
        {
            //Initialize the array with a maximum of the MaxClients from the config file.
            client = new Client[Properties.Settings.Default.MaxNumberOfClients];

            //Create a new Listener object
            listener = new Listener(port);
            listener.userAdded += new ConnectionEvent(listener_userAdded);
            listener.Start();

            //Create the readers and writers.
            readStream = new MemoryStream();
            writeStream = new MemoryStream();
            reader = new BinaryReader(readStream);
            writer = new BinaryWriter(writeStream);

            //Set the singleton to the current object
            Server.singleton = this;
        }

        /// <summary>
        /// Method that is performed when a new user is added.
        /// </summary>
        /// <param name="sender">The object that sent this message</param>
        /// <param name="user">The user that needs to be added</param>
        private void listener_userAdded(object sender, Client user)
        {
            connectedClients++;

            //Send a message to every other client notifying them on a new client, if the setting is set to True
            if (Properties.Settings.Default.SendMessageToClientsWhenAUserIsAdded)
            {
                writeStream.Position = 0;

                //Write in the form {Protocol}{User_ID}{User_IP}
                writer.Write(Properties.Settings.Default.NewPlayerByteProtocol);
                writer.Write(user.id);
                /*writer.Write(user.usernmae);
                writer.Write(user.password);
         
                */
                writer.Write(user.IP);

                SendData(GetDataFromMemoryStream(writeStream), user);
            }

            //Set up the events
            user.DataReceived += new DataReceivedEvent(user_DataReceived);
            user.UserDisconnected += new ConnectionEvent(user_UserDisconnected);

            //Print the new player message to the server window.
            Console.WriteLine(user.ToString() + " connected\tConnected Clients:  " + connectedClients + "\n");
         
            //Add to the client array
            client[user.id] = user;
        }

        /// <summary>
        /// Method that is performed when a new user is disconnected.
        /// </summary>
        /// <param name="sender">The object that sent this message</param>
        /// <param name="user">The user that needs to be disconnected</param>
        private void user_UserDisconnected(object sender, Client user)
        {
            connectedClients--;

            //Send a message to every other client notifying them on a removed client, if the setting is set to True
            if (Properties.Settings.Default.SendMessageToClientsWhenAUserIsRemoved)
            {
                writeStream.Position = 0;

                //Write in the form {Protocol}{User_ID}{User_IP}
                writer.Write(Properties.Settings.Default.DisconnectedPlayerByteProtocol);
                writer.Write(user.id);
                writer.Write(user.IP);

                SendData(GetDataFromMemoryStream(writeStream), user);
            }

            //Print the removed player message to the server window.
            Console.WriteLine(user.ToString() + " disconnected\tConnected Clients:  " + connectedClients + "\n");

            //Clear the array's index
            client[user.id] = null;
        }

        /// <summary>
        /// Relay messages sent from one client and send them to others
        /// </summary>
        /// <param name="sender">The object that called this method</param>
        /// <param name="data">The data to relay</param>
        private void user_DataReceived(Client sender, byte[] data)
        {
            writeStream.Position = 0;

            if (Properties.Settings.Default.EnableSendingIPAndIDWithEveryMessage)
            {
                //Append the id and IP of the original sender to the message, and combine the two data sets.
                writer.Write(sender.id);
                writer.Write(sender.IP);
                data = CombineData(data, writeStream);
            }

            //If we want the original sender to receive the same message it sent, we call a different method
            if (Properties.Settings.Default.SendBackToOriginalClient)
            {
                SendData(data);
            }
            else
            {
                SendData(data, sender);
            }
        }

        /// <summary>
        /// Converts a MemoryStream to a byte array
        /// </summary>
        /// <param name="ms">MemoryStream to convert</param>
        /// <returns>Byte array representation of the data</returns>
        private byte[] GetDataFromMemoryStream(MemoryStream ms)
        {
            byte[] result;

            //Async method called this, so lets lock the object to make sure other threads/async calls need to wait to use it.
            lock (ms)
            {
                int bytesWritten = (int)ms.Position;
                result = new byte[bytesWritten];

                ms.Position = 0;
                ms.Read(result, 0, bytesWritten);
            }

            return result;
        }

        /// <summary>
        /// Combines one byte array with a MemoryStream
        /// </summary>
        /// <param name="data">Original Message in byte array format</param>
        /// <param name="ms">Message to append to the original message in MemoryStream format</param>
        /// <returns>Combined data in byte array format</returns>
        private byte[] CombineData(byte[] data, MemoryStream ms)
        {
            //Get the byte array from the MemoryStream
            byte[] result = GetDataFromMemoryStream(ms);

            //Create a new array with a size that fits both arrays
            byte[] combinedData = new byte[data.Length + result.Length];

            //Add the original array at the start of the new array
            for (int i = 0; i < data.Length; i++)
            {
                combinedData[i] = data[i];
            }

            //Append the new message at the end of the new array
            for (int j = data.Length; j < data.Length + result.Length; j++)
            {
                combinedData[j] = result[j - data.Length];
            }

            //Return the combined data
            return combinedData;
        }

        /// <summary>
        /// Sends a message to every client except the source.
        /// </summary>
        /// <param name="data">Data to send</param>
        /// <param name="sender">Client that should not receive the message</param>
        private void SendData(byte[] data, Client sender)
        {
            foreach (Client c in client)
            {
                if (c != null && c != sender)
                {
                    c.SendData(data);
                }
            }

            //Reset the writestream's position
            writeStream.Position = 0;
        }

        /// <summary>
        /// Sends data to all clients
        /// </summary>
        /// <param name="data">Data to send</param>
        private void SendData(byte[] data)
        {
            foreach (Client c in client)
            {
                if (c != null)
                    c.SendData(data);
            }

            //Reset the writestream's position
            writeStream.Position = 0;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace TomShane.Neoforce.Central.Code
{
    public class Listener
    {
        private TcpListener listener;
        int MaxNumberOfClients = 2;
        //send an even once we receive a user
        public event ConnectionEvent userAdded;


        //a variable to keep track of how many users we've added
        private bool[] usedUserID;

        /// <summary>
        /// Create a new Listener object
        /// </summary>
        /// <param name="portNr">Port to use</param>
        public Listener(int portNr)
        {
            //Create an array to hold the used IDs
            usedUserID = new bool[MaxNumberOfClients];

            //Create the internal TcpListener
            listener = new TcpListener(IPAddress.Any, portNr);
        }

        /// <summary>
        /// Starts a new session of listening for messages.
        /// </summary>
        public void Start()
        {
            listener.Start();
            ListenForNewClient();
        }

        /// <summary>
        /// Stops listening for messages.
        /// </summary>
        public void Stop()
        {
            listener.Stop();
        }

        /// <summary>
        /// Used for allowing new users to connect
        /// </summary>
        private void ListenForNewClient()
        {
            listener.BeginAcceptTcpClient(AcceptClient, null);
        }

        /// <summary>
        /// Called when a client connects to the server
        /// </summary>
        /// <param name="ar">Status of the Async method</param>
        private void AcceptClient(IAsyncResult ar)
        {
            //We need to end the Async method of accepting new clients
            TcpClient client = listener.EndAcceptTcpClient(ar);

            //id is originally -1 which means a user cannot connect
            int id = -1;
            for (byte i = 0; i < usedUserID.Length; i++)
            {
                if (usedUserID[i] == false)
                {
                    id = i;
                    break;
                }
            }

            //If the id is still -1, the client what wants to connect cannot (probably because we have reached the maximum number of clients
            if (id == -1)
            {
                Console.WriteLine("Client " + client.Client.RemoteEndPoint.ToString() + " cannot connect. ");
                return;
            }

            //ID is valid, so create a new Client object with the server ID and IP
            usedUserID[id] = true;
            Client newClient = new Client(client,(byte)id);

            //We are now connected, so we need to set up the User Disconnected event for this user.
            newClient.UserDisconnected += new ConnectionEvent(client_UserDisconnected);

            //We are now connected, so call all delegates of the UserAdded event.
            if (userAdded != null)
                userAdded(this, newClient);

            //Begin listening for new clients
            ListenForNewClient();
        }

        /// <summary>
        /// User disconnects from the server
        /// </summary>
        /// <param name="sender">Original object that called this method</param>
        /// <param name="user">Client to disconnect</param>
        void client_UserDisconnected(object sender, Client user)
        {
            usedUserID[user.id] = false;
        }

    }
}

namespace TomShane.Neoforce.Central
{
  public partial class MainWindow: Window
  {
      TcpClient cliente;
      string Ip = "127.0.0.1";
      int porta = 1490;
      int BUFFER_SIZE = 2048;
      byte[] readBuffer;
      MemoryStream readStream, writeStream;
      BinaryReader reader;
      BinaryWriter writer;
      string username = "Ola";
      string password = "ola";
    //  BinaryWriter write;
     
      #region //// Fields ////////////

      ////////////////////////////////////////////////////////////////////////////       
    private Texture2D defaultbg;
    private Texture2D greenbg;
    
    private SideBar sidebar = null;

    private SideBarPanel pnlRes = null;
   // private RadioButton rdbRes1024 = null;
   // private RadioButton rdbRes1280 = null;
    //private RadioButton rdbRes1680 = null;
   // private CheckBox chkResFull = null;
    private Button btnApply = null;
    private Button btnExit = null;

    private SideBarPanel pnlTasks = null;
    private Button btnRandom = null;
    private Button btnClose = null; 
        
    private Button[] btnTasks = null;

    private SideBarPanel pnlSkin = null;
   // private RadioButton rdbDefault = null;
   // private RadioButton rdbGreen = null;            
        
    private SideBarPanel pnlStats = null;
    public Label lblObjects = null;
    public Label lblAvgFps = null;    
    public Label lblFps = null;
    private TextBox txusername = null;
    private TextBox txpassword = null;
    private Label lbusername = null;
    private Label lbpassword = null;
    ////////////////////////////////////////////////////////////////////////////
    
    #endregion

    #region Classe de incritação
    public static bool Check(String localpassword, String passwordInDb)
    {
        if (localpassword == null || string.IsNullOrEmpty(passwordInDb))
            throw new ArgumentException();

        String[] arr = passwordInDb
            .Split(":".ToCharArray(), 2, StringSplitOptions.RemoveEmptyEntries);

        if (arr.Length == 2)
        {
            // new format as {HASH}:{SALT}
            String cryptpass = arr[0];
            String salt = arr[1];

            return CreateMd5Hash(localpassword + salt).Equals(cryptpass);
        }
        else
        {
            // old format as {HASH} just like PHPbb and many other apps
            String cryptpass = passwordInDb;

            return CreateMd5Hash(localpassword).Equals(cryptpass);
        }
    }
  
    public static String Create(String passwd)
    {
        var rnd = new Random();
        var saltBuf = new StringBuilder();
        const string seedList = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

        for (int i = 0; i < 32; i++)
        {
            int rndIndex = rnd.Next(62);
            saltBuf.Append(seedList.Substring(rndIndex, 1));
        }

        String salt = saltBuf.ToString();

        return CreateMd5Hash(passwd + salt) + ":" + salt;
    }
    /** Takes the MD5 hash of a sequence of ASCII or LATIN1 characters,
    *  and returns it as a 32-character lowercase hex string.
    *
    *  Equivalent to MySQL's MD5() function
    *  and to perl's Digest::MD5::md5_hex(),
    *  and to PHP's md5().
    *
    *  Does no error-checking of the input,  but only uses the low 8 bits
    *  from each input character.
    */
    private static String CreateMd5Hash(String data)
    {
        byte[] bdata = new byte[data.Length];
        byte[] hash;
        for (int i = 0; i < data.Length; i++)
        {
            bdata[i] = (byte)(data[i] & 0xff);
        }
        try
        {
            MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider();
            hash = md5Provider.ComputeHash(bdata);
        }
        catch (SecurityException e)
        {
            throw new ApplicationException("A security encryption error occured.", e);
        }
        var result = new StringBuilder(32);
        foreach (byte t in hash)
        {
            String x = (t & 0xff).ToString("X").ToLowerInvariant();
            if (x.Length < 2)
            {
                result.Append("0");
            }
            result.Append(x);
        }
        return result.ToString();
    }
    private static String CalculateHash(string password, string salt)
    {
        byte[] data = System.Text.Encoding.ASCII.GetBytes(salt + password);
        data = System.Security.Cryptography.MD5.Create().ComputeHash(data);
        return BitConverter.ToString(data).Replace("-", "") + ":" + salt;
    }
    #endregion

    private void StreamReceived(System.IAsyncResult ar)
    {
        int bytesRead = 0;

        try
        {
            lock (cliente.GetStream())
            {

                bytesRead = cliente.GetStream().EndRead(ar);
            }
        }
        catch (Exception ex)
        {
            TomShane.Neoforce.Controls.MessageBox.Show(Manager, TomShane.Neoforce.Controls.MessageBox.MessageBoxType.CANCEL, "ALGO CORREU MAL" + ex.Message, "");
        }
        if (bytesRead == 0)
        {
            cliente.Close();
            return;
        }
        byte[] data = new byte[bytesRead];
        for (int i = 0; i < bytesRead; i++)
            data[i] = readBuffer[1];
        ProcessData(data);
        cliente.GetStream().BeginRead(readBuffer, 0, BUFFER_SIZE, StreamReceived, null);
    }

    private void ProcessData(byte[] data)
    {
        readStream.SetLength(0);
        readStream.Position = 0;

        readStream.Write(data, 0, data.Length);
        readStream.Position = 0;
        Protocol p;
        try
        {
            p = (Protocol)reader.ReadByte();
            if (p == Protocol.Connected)
            {
                byte id = reader.ReadByte();
                string ip = reader.ReadString();
                string username = reader.ReadString();
               string password = reader.ReadString();
                TomShane.Neoforce.Controls.MessageBox.Show(Manager, TomShane.Neoforce.Controls.MessageBox.MessageBoxType.CANCEL, "CONNECTADO", "");
                writeStream.Position = 0;
                writer.Write("HELLO");
                //write.Write(password);
               
                SendData(GetDataFromMemoryStream(writeStream));
            }
            else if (p == Protocol.Disconneted)
            {
                byte id = reader.ReadByte();
                string ip = reader.ReadString();
               // string username = reader.ReadString();
               // string password = reader.ReadString();
                TomShane.Neoforce.Controls.MessageBox.Show(Manager, TomShane.Neoforce.Controls.MessageBox.MessageBoxType.CANCEL, "DESCONECTADO", "");

            }
        }
        catch (Exception ex)
        {
            TomShane.Neoforce.Controls.MessageBox.Show(Manager, TomShane.Neoforce.Controls.MessageBox.MessageBoxType.CANCEL, "ALGO CORREU MAL" + ex.Message, "");

        }

    }
    private byte[] GetDataFromMemoryStream(MemoryStream ms)
    {
        byte[] result;

        //Async method called this, so lets lock the object to make sure other threads/async calls need to wait to use it.
        lock (ms)
        {
            int bytesWritten = (int)ms.Position;
            result = new byte[bytesWritten];

            ms.Position = 0;
            ms.Read(result, 0, bytesWritten);
        }

        return result;
    }
    public void SendData(byte[] b)
    {
        //Try to send the data.  If an exception is thrown, disconnect the client
        try
        {
            lock (cliente.GetStream())
            {
                cliente.GetStream().BeginWrite(b, 0, b.Length, null, null);
            }
        }
        catch (Exception e)
        {
            TomShane.Neoforce.Controls.MessageBox.Show(Manager, TomShane.Neoforce.Controls.MessageBox.MessageBoxType.CANCEL, "ALGO CORREU MAL"+e, "");
         
        }
    }
    #region //// Constructors //////


    ////////////////////////////////////////////////////////////////////////////
    public MainWindow(Manager manager): base(manager)
    {
       
      greenbg = Manager.Content.Load<Texture2D>("Content\\Images\\Green");
      defaultbg = Manager.Content.Load<Texture2D>("Content\\Images\\Default");
      (Manager.Game as Application).BackgroundImage = defaultbg;     

      InitControls();
      try
      {
          cliente = new TcpClient();
          //client = new TcpClient();
          cliente.NoDelay = true;
          cliente.Connect(Ip, porta);
          readBuffer = new byte[BUFFER_SIZE];
          cliente.GetStream().BeginRead(readBuffer, 0, BUFFER_SIZE, StreamReceived, null);
          readStream = new MemoryStream();
          writeStream = new MemoryStream();
          reader = new BinaryReader(readStream);
          writer = new BinaryWriter(writeStream);
        //  write = new BinaryWriter(writeStream);
      }
      catch (Exception) {
          
          TomShane.Neoforce.Controls.MessageBox.Show(Manager, TomShane.Neoforce.Controls.MessageBox.MessageBoxType.CANCEL, "ALGO CORREU MAL" , "");
          //Close();
      
      } 
      //cliente.loginvalidade(Username,Password);
    }
    ////////////////////////////////////////////////////////////////////////////

    #endregion

    #region //// Methods ///////////
    public Button LoginButton { get { return btnApply; } }
    public Button ExitButton { get { return btnExit; } }
    public string Username { get { return txusername.Text; } }
    public string Password { get { return txpassword.Text; } }
    ////////////////////////////////////////////////////////////////////////////
    private void InitControls()
    {                  
      sidebar = new SideBar(Manager);            
      sidebar.Init();
      sidebar.StayOnBack = true;
      sidebar.Passive = true;            
      sidebar.Width = 940;
      sidebar.Height = ClientHeight;
      sidebar.Anchor = Anchors.Left | Anchors.Top | Anchors.Bottom;
         
      Add(sidebar);
                 
      InitRes();
   //  InitTasks();
    InitStats(); 
      InitSkins();        
     // InitConsole();                       
    }
    ////////////////////////////////////////////////////////////////////////////   
        

    ////////////////////////////////////////////////////////////////////////////
    private void InitRes()
    {
  
  pnlRes = new SideBarPanel(Manager);
      pnlRes.Init();
      pnlRes.Passive = true;
      pnlRes.Parent = sidebar;      
      pnlRes.Left = 16;
      pnlRes.Top = 16;
      pnlRes.Width = sidebar.Width - pnlRes.Left;
      pnlRes.Height = 0;      
      pnlRes.CanFocus = false;
        
      lbusername = new Label(Manager);
      lbusername.Init();
      lbusername.Width = 100;
      lbusername.Parent = sidebar;
      lbusername.Top = pnlRes.Left + lbusername.Width + 100;
      lbusername.Left = pnlRes.Top + pnlRes.Height + 200;
      lbusername.Text = "USERNAME";
      txusername = new TextBox(Manager);
      txusername.Init();
      txusername.Width = 200;
      txusername.Parent = sidebar;
      txusername.Top = pnlRes.Left + txusername.Width + 0;
      txusername.Left = pnlRes.Top + pnlRes.Height + 290;
      txusername.Text.Trim();
      lbpassword = new Label(Manager);
      lbpassword.Init();
      lbpassword.Width = 100;
      lbpassword.Parent = sidebar;
      lbpassword.Top = pnlRes.Left + lbpassword.Width+130 ;
      lbpassword.Left = pnlRes.Top + pnlRes.Height + 200;
     
      
   
      lbpassword.Text = "PASSWORD";
      txpassword = new TextBox(Manager);
      txpassword.Mode = TextBoxMode.Password;
      txpassword.PasswordChar = '*';
        txpassword.Init();
      
        txpassword.Width = 200;
      txpassword.Parent = sidebar;
      txpassword.Top = pnlRes.Left + txpassword.Width+30;
      txpassword.Left = pnlRes.Top + pnlRes.Height + 290;
      
      
      txpassword.Text.Trim();
       /*
      rdbRes1024 = new RadioButton(Manager);
      rdbRes1024.Init();
      rdbRes1024.Parent = pnlRes;
      rdbRes1024.Left = 8;
      rdbRes1024.Width = pnlRes.Width - rdbRes1024.Left * 2;
      rdbRes1024.Height = 16;
      rdbRes1024.Text = "Resolution 1024x768";
      rdbRes1024.Top = 8;
      rdbRes1024.Checked = true;

      rdbRes1280 = new RadioButton(Manager);
      rdbRes1280.Init();
      rdbRes1280.Parent = pnlRes;
      rdbRes1280.Left = rdbRes1024.Left;
      rdbRes1280.Width = rdbRes1024.Width;
      rdbRes1280.Height = rdbRes1024.Height;
      rdbRes1280.Text = "Resolution 1280x1024";
      rdbRes1280.Top = 24;

      rdbRes1680 = new RadioButton(Manager);
      rdbRes1680.Init();
      rdbRes1680.Parent = pnlRes;
      rdbRes1680.Left = rdbRes1024.Left;
      rdbRes1680.Width = rdbRes1024.Width;
      rdbRes1680.Height = rdbRes1024.Height;
      rdbRes1680.Text = "Resolution 1680x1050";
      rdbRes1680.Top = 40;

      chkResFull = new CheckBox(Manager);
      chkResFull.Parent = pnlRes;
      chkResFull.Init();
      chkResFull.Left = rdbRes1024.Left;
      chkResFull.Width = rdbRes1024.Width;
      chkResFull.Height = rdbRes1024.Height;
      chkResFull.Text = "Fullscreen Mode";
      chkResFull.Top = 64;      
        */
      btnApply = new Button(Manager);
      btnApply.Init();
      btnApply.Width = 80;
      btnApply.Parent = sidebar;
      btnApply.Left = pnlRes.Left + btnApply.Width + 220;      
      btnApply.Top = pnlRes.Top + pnlRes.Height + 300;
      btnApply.Text = "Apply";
      btnApply.Click += new Controls.EventHandler(btnApply_Click);

      btnExit = new Button(Manager);
      btnExit.Init();
      btnExit.Width = 80;
      btnExit.Parent = sidebar;
      btnExit.Left = btnApply.Left + btnApply.Width +8;
      btnExit.Top = pnlRes.Top + pnlRes.Height + 300;
      btnExit.Text = "Exit";
      btnExit.Click += new Controls.EventHandler(btnExit_Click);            
    }
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////    
    private void InitTasks()
    {
      pnlTasks = new SideBarPanel(Manager);
      pnlTasks.Init();
      pnlTasks.Passive = true;
      pnlTasks.Parent = sidebar;      
      pnlTasks.Left = 16;
      pnlTasks.Width = sidebar.Width - pnlRes.Left;
      pnlTasks.Height = (TasksCount * 25) + 16;
      pnlTasks.Top = btnApply.Top + btnApply.Height + 16;
      pnlTasks.CanFocus = false;      

      btnTasks = new Button[TasksCount];
      for (int i = 0; i < TasksCount; i++)
      {
        btnTasks[i] = new Button(Manager);
        btnTasks[i].Init();
        btnTasks[i].Parent = pnlTasks;
        btnTasks[i].Left = 8;
        btnTasks[i].Top = 8 + i * (btnTasks[i].Height + 1);
        btnTasks[i].Width = -8 + btnApply.Width * 2;
        btnTasks[i].Click += new TomShane.Neoforce.Controls.EventHandler(btnTask_Click);
        btnTasks[i].Text = "Task [" + i.ToString() + "]";
        if (Tasks.Length >= i - 1 && Tasks[i] != "") btnTasks[i].Text = Tasks[i];
      }

      btnRandom = new Button(Manager);      
      btnRandom.Init();
      btnRandom.Parent = sidebar;
      btnRandom.Width = 80;
      btnRandom.Left = 16;
      btnRandom.Top = pnlTasks.Top + pnlTasks.Height + 8;
      btnRandom.Text = "Random";
      btnRandom.Click += new Controls.EventHandler(btnRandom_Click);

      btnClose = new Button(Manager);
      btnClose.Init();
      btnClose.Width = 80;      
      btnClose.Parent = sidebar;
      btnClose.Left = btnRandom.Left + btnRandom.Width + 8;
      btnClose.Top = pnlTasks.Top + pnlTasks.Height + 8; ;
      btnClose.Text = "Close";
      btnClose.Click += new Controls.EventHandler(btnClose_Click);
    }
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////    
    private void InitSkins()
    {            
      pnlSkin = new SideBarPanel(Manager);
      pnlSkin.Init();
      pnlSkin.Passive = true;
      pnlSkin.Parent = sidebar;     
      pnlSkin.Left = 16;
      pnlSkin.Width = sidebar.Width - pnlRes.Left;
      pnlSkin.Height = 44;
      pnlSkin.Top = ClientHeight - 16 - pnlStats.Height - pnlSkin.Height - 16; 
      pnlSkin.Anchor = Anchors.Left | Anchors.Bottom;
      pnlSkin.CanFocus = false;

  /*    rdbDefault = new RadioButton(Manager);
      rdbDefault.Init();
      rdbDefault.Parent = pnlSkin;
      rdbDefault.Left = 8;
      rdbDefault.Width = pnlSkin.Width - rdbDefault.Left * 2;
      rdbDefault.Height = 16;
      rdbDefault.Text = "Default Skin";
      rdbDefault.Top = 8;
      rdbDefault.Checked = Manager.Skin.Name == "Default";
      rdbDefault.Click += new Controls.EventHandler(rdbDefault_Click);

      rdbGreen = new RadioButton(Manager);
      rdbGreen.Init();
      rdbGreen.Parent = pnlSkin;
      rdbGreen.Left = 8;
      rdbGreen.Width = pnlSkin.Width - rdbGreen.Left * 2;
      rdbGreen.Height = 16;
      rdbGreen.Text = "Green Skin";
      rdbGreen.Top = 24;
      rdbGreen.Checked = Manager.Skin.Name == "Green";
      rdbGreen.Click += new Controls.EventHandler(rdbGreen_Click);
      rdbGreen.Enabled = true;
    
   */}
    ////////////////////////////////////////////////////////////////////////////
            
    ////////////////////////////////////////////////////////////////////////////    
    private void InitStats()
    {
      pnlStats = new SideBarPanel(Manager);
      pnlStats.Init();
      pnlStats.Passive = true;
      pnlStats.Parent = sidebar;      
      pnlStats.Left = 16;      
      pnlStats.Width = sidebar.Width - pnlStats.Left;
      pnlStats.Height = 64;
      pnlStats.Top = ClientHeight - 16 - pnlStats.Height;      
      pnlStats.Anchor = Anchors.Left | Anchors.Bottom;
      pnlStats.CanFocus = false;      
      
      lblObjects = new Label(Manager);
      lblObjects.Init();    
      lblObjects.Parent = pnlStats;        
      lblObjects.Left = 8;
      lblObjects.Top = 8;
      lblObjects.Height = 16;
      lblObjects.Width = pnlStats.Width - lblObjects.Left * 2;;      
      lblObjects.Alignment = Alignment.MiddleLeft;                 

      lblAvgFps = new Label(Manager);
      lblAvgFps.Init();
      lblAvgFps.Parent = pnlStats;   
      lblAvgFps.Left = 8;
      lblAvgFps.Top = 24;
      lblAvgFps.Height = 16;
      lblAvgFps.Width = pnlStats.Width - lblObjects.Left * 2;
      lblAvgFps.Alignment = Alignment.MiddleLeft;      

      lblFps = new Label(Manager);
      lblFps.Init();
      lblFps.Parent = pnlStats;
      lblFps.Left = 8;
      lblFps.Top = 40;
      lblFps.Height = 16;
      lblFps.Width = pnlStats.Width - lblObjects.Left * 2;
      lblFps.Alignment = Alignment.MiddleLeft;      
    }  
    ////////////////////////////////////////////////////////////////////////////    

    ////////////////////////////////////////////////////////////////////////////
   /* private void InitConsole()
    {
      TabControl tbc = new TabControl(Manager);
      TomShane.Neoforce.Controls.Console con1 = new TomShane.Neoforce.Controls.Console(Manager);
      TomShane.Neoforce.Controls.Console con2 = new TomShane.Neoforce.Controls.Console(Manager);      
      
      // Setup of TabControl, which will be holding both consoles
      tbc.Init();
      tbc.AddPage("Global");
      tbc.AddPage("Private");                 

      tbc.Alpha = 220;
      tbc.Left = 220;
      tbc.Height = 220;
      tbc.Width = 400;
      tbc.Top = Manager.TargetHeight - tbc.Height - 32;      
      
      tbc.Movable = true;
      tbc.Resizable = true;
      tbc.MinimumHeight = 96;
      tbc.MinimumWidth = 160;   
                       
      tbc.TabPages[0].Add(con1);
      tbc.TabPages[1].Add(con2);      
                              
      con1.Init();
      con2.Init();           
      
      con2.Width = con1.Width = tbc.TabPages[0].ClientWidth;
      con2.Height = con1.Height = tbc.TabPages[0].ClientHeight;
      con2.Anchor = con1.Anchor = Anchors.All;                

      con1.Channels.Add(new ConsoleChannel(0, "General", Color.Orange));
      con1.Channels.Add(new ConsoleChannel(1, "Private", Color.White));
      con1.Channels.Add(new ConsoleChannel(2, "System", Color.Yellow));           
      
      // We want to share channels and message buffer in both consoles
      con2.Channels = con1.Channels;
      con2.MessageBuffer = con1.MessageBuffer;                       
      
      // In the second console we display only "Private" messages
      con2.ChannelFilter.Add(1);            
      
      // Select default channels for each tab
      con1.SelectedChannel = 0;
      con2.SelectedChannel = 1;
      
      // Do we want to add timestamp or channel name at the start of every message?
      con1.MessageFormat = ConsoleMessageFormats.All;
      con2.MessageFormat = ConsoleMessageFormats.TimeStamp;

      // Handler for altering incoming message
      con1.MessageSent += new ConsoleMessageEventHandler(con1_MessageSent);      
      
      // We send initial welcome message to System channel
      con1.MessageBuffer.Add(new ConsoleMessage("Welcome to Neoforce!", 2,username));
                    
      Manager.Add(tbc);      
    }
    ////////////////////////////////////////////////////////////////////////////
    
    ////////////////////////////////////////////////////////////////////////////
    void con1_MessageSent(object sender, ConsoleMessageEventArgs e)
    {
      if (e.Message.Channel == 0)
      {
        //e.Message.Text = "(!) " + e.Message.Text;
      }
    }
    ////////////////////////////////////////////////////////////////////////////
      */  
    #endregion
    
  }
}

não me da nenhum erro

ele connecta-se ao servidor mas não envia para servidor o username e password

alguem me pode ajudar

Compartilhar este post


Link para o post
Compartilhar em outros sites

mudei todo o cliente e servidor classes mas me esta a dar o seguinte erro

Error 1 The name 'InvokeRequired' does not exist in the current context D:\GAMES\TomShane.Neoforce.Controls.XNA4\Neoforce\Source\Central\Code\Layout.cs 294 14 Central
Error 2 The name 'Invoke' does not exist in the current context D:\GAMES\TomShane.Neoforce.Controls.XNA4\Neoforce\Source\Central\Code\Layout.cs 295 13 Central
estou a usar o xna com neoforce
  private void ProcessComplete(Headers header,ErrorCodes Erro){
         if (InvokeRequired) {
            Invoke(new ProcessesCompleteDel(ProcessComplete), header, Erro);
             return;

         } if (header != Headers.Login) {
             return;
         } if (Erro == ErrorCodes.Sucess)
         {

             TomShane.Neoforce.Controls.MessageBox.Show(Manager, TomShane.Neoforce.Controls.MessageBox.MessageBoxType.CANCEL, "Wecome,{0}" + Username, "");
             server ola = new server(Manager, txusername.Text.Trim());
             //Close();
             // this.Hide();
             //server ola = new server(Manager, txusername.Text.Trim(),txpassword.Text.Trim());
             ola.Init();
             ola.StayOnTop = true;

             //Manager.Add(ola);
             ola.Visible = false;
             ola.Width = 800;
             ola.Height = 600;
             ola.CloseButtonVisible = false;
             ola.Center();
             ola.Movable = false;
             ola.Shadow = false;
             ola.Show();


             txusername.Hide();
             txpassword.Hide();
             lbusername.Hide();
             lbpassword.Hide();
             btnApply.Hide();
             btnExit.Hide();

         }
         else
         {
             string msg = "";
             switch (Erro) { 
                 case ErrorCodes.InvalidLogin:
                     msg = "username \\Password is incorrect";
                     break;
                 case ErrorCodes.Error:
                     msg = "ERRO NO MAASA";
                     break;
             }
             TomShane.Neoforce.Controls.MessageBox.Show(Manager, TomShane.Neoforce.Controls.MessageBox.MessageBoxType.ERROR, "Wecome,{0}" + msg, "");
       
         }
     }

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.