Exemple #1
0
 /*
  * private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  * {
  *  if (Running) { backgroundWorker1.RunWorkerAsync(); }
  *  if (!Running) { button1.Enabled = true; lblTest.Text = "Offline"; }
  * }
  *
  * private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  * {
  *  string[] Log = new string[2];
  *  if (Running)
  *  {
  *      Socket LoggingIn;
  *      LoggingIn = listeningSocket.Accept();
  *      Thread NewThread = new Thread(new ParameterizedThreadStart(HandleClient));
  *
  *      //Login
  *      string[] Recieved = new string[4];
  *      Recieved = Recieve(LoggingIn).Split('\n');
  *      if (Recieved[0] == "LOG")
  *      {
  *          if (Recieved[1] == "New")
  *          {
  *              string[] UAP = new string[3];
  *              UAP = Recieved[2].Split(';');
  *              Log = Login(false, UAP[0], Decrypt(UAP[1]), LoggingIn, UAP[2],UAP[3]).Split(';');
  *              if (Log[0] == "True")
  *              {
  *                  //Logged In
  *                  Clients[ClientCount, 0] = UAP[0];   //Username
  *                  Clients[ClientCount, 1] = UAP[2];   //DisplayName
  *                  Clients[ClientCount, 2] = LoggingIn.RemoteEndPoint.ToString(); // IP
  *                  Clients[ClientCount, 3] = ClientCount.ToString();       //Index in Socket Array
  *                  ClientSocks[ClientCount] = LoggingIn;
  *
  *                  Logins[Accounts, 0] = UAP[0];
  *                  Logins[Accounts, 1] = Decrypt(UAP[1]);
  *                  Logins[Accounts, 2] = true.ToString();
  *                  Logins[Accounts, 3] = UAP[2];
  *                  Logins[Accounts, 4] = UAP[3];
  *
  *
  *
  *                  ClientCount++;
  *                  Accounts++;
  *
  *                  //Expand Client Array
  *                  string[,] ClientsBU = Clients;
  *                  Clients = new string[ClientCount+1,4];
  *                  for (int c = 0; c < ClientCount; c++)
  *                  {
  *                      for (int k = 0; k < 4; k++)
  *                      {
  *                          Clients[c, k] = ClientsBU[c,k];
  *                      }
  *                  }
  *
  *                  //Expand Login Array
  *                  string[,] LoginsBU = Logins;
  *                  Logins = new string[Accounts + 1, 5];
  *                  for (int c = 0; c < Accounts; c++)
  *                  {
  *                      for (int k = 0; k < 5; k++)
  *                      {
  *                          Logins[c, k] = LoginsBU[c, k];
  *                      }
  *                  }
  *
  *                  Array.Resize(ref ClientSocks,ClientCount+1);
  *                  UpdateLoginsFile();
  *                  lbReqUpdate = true;
  *                  NewThread.Start(ClientCount - 1);
  *              }
  *              else { LoggingIn.Close(); }
  *
  *          }
  *          else if (Recieved[1] == "Old")
  *          {
  *              string[] UAP = new string[2];
  *              UAP = Recieved[2].Split(';');
  *              Log = Login(true, UAP[0], Decrypt(UAP[1]), LoggingIn).Split(';');
  *              if (Log[0] == "True")
  *              {
  *                  //Logged In
  *                  Clients[ClientCount, 0] = UAP[0];   //Username
  *                  Clients[ClientCount, 1] = Logins[int.Parse(Log[1]),3];   //DisplayName
  *                  Clients[ClientCount, 2] = LoggingIn.RemoteEndPoint.ToString(); // IP
  *                  Clients[ClientCount, 3] = ClientCount.ToString();       //Index in Socket Array
  *                  ClientSocks[ClientCount] = LoggingIn;
  *
  *                  Logins[int.Parse(Log[1]), 2] = true.ToString();
  *
  *                  ClientCount++;
  *
  *                  //Expand Client Array
  *                  string[,] ClientsBU = Clients;
  *                  Clients = new string[ClientCount + 2, 4];
  *                  for (int c = 0; c < ClientCount; c++)
  *                  {
  *                      for (int k = 0; k < 4; k++)
  *                      {
  *                          Clients[c, k] = ClientsBU[c, k];
  *                      }
  *                  }
  *
  *                  Array.Resize(ref ClientSocks, ClientCount + 1);
  *                  lbReqUpdate = true;
  *
  *
  *                  NewThread.Start(ClientCount - 1);
  *
  *              }else{ LoggingIn.Close();}
  *
  *          }
  *      }
  *  }
  * }
  */
 private void button2_Click(object sender, EventArgs e)
 {
     Running      = false;
     lblTest.Text = "Stopping";
     THLogins.Abort();
     listeningSocket.Close();
     //backgroundWorker1.CancelAsync();
     for (int c = 0; c < Logins.GetUpperBound(0); c++)
     {
         Logins[c, 2] = false.ToString();
     }
     for (int c = 0; c < ClientSocks.Length - 1; c++)
     {
         Send("STS", "UPD", "Server Shutting Down", ClientSocks[c]);
         ClientCount--;
         ClientSocks[c].Close();
     }
     //while (backgroundWorker1.IsBusy) { }
     listeningSocket = new Socket(MyLocalIp.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     THLogins        = new Thread(new ThreadStart(HandleNewCons));
     lblTest.Text    = "Offline";
     timer1.Enabled  = false;
     Clients         = new string[1, 4];//Rows,Columns, 1 Row per Client, Username, DisplayName,I.P. Address or DC timestamp, Index in client socket array
     ClientSocks     = new Socket[1];
     UpdateListbox();
     button1.Enabled = true;
 }
Exemple #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     button1.Enabled = false;
     if (listeningSocket == null)
     {
         listeningSocket = new Socket(MyLocalIp.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     }
     Running = true;
     listeningSocket.Bind(myEP);
     listeningSocket.Listen(922);
     //backgroundWorker1.RunWorkerAsync();
     THLogins.Start();
     timer1.Enabled = true;
     lblTest.Text   = "Running";
 }