Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using System.Net.Sockets;
  6.  
  7. namespace GL_Zombie_Server
  8. {
  9.     public class NetworkClient
  10.     {
  11.         public string Username = "";
  12.         public string Password = "";
  13.         public bool Connected = true;
  14.         System.IO.StreamReader SR;
  15.         System.IO.StreamWriter SW;
  16.         //public event ReadyToReconnect Recieved;
  17.         public int Number;
  18.         bool Send = false;
  19.         public byte[] Buffer;
  20.         System.Net.Sockets.TcpListener TcpListener;
  21.         System.Net.Sockets.TcpClient TcpClient;
  22.         ZombieDB ZDB = new ZombieDB();
  23.  
  24.         System.Threading.Thread Thread;
  25.         System.Timers.Timer T = new System.Timers.Timer(175);
  26.         string ipaddress;
  27.         int port;
  28.         public NetworkClient(string ipaddress, int port)//, string Username, string Password)
  29.         {
  30.             this.ipaddress = ipaddress;
  31.             this.port = port;
  32.             /*this.Username = Username;
  33.             this.Password = Password;*/
  34.             //PTS += new System.Threading.ParameterizedThreadStart(NewThread);
  35.            
  36.             Thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(NewThread));
  37.             Thread.Start();
  38.         }
  39.         public void SendData(string Data)
  40.         {
  41.             SW.Write(Data);
  42.             SW.Flush();
  43.         }
  44.         void T_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  45.         {
  46.             while (TcpClient.GetStream().DataAvailable)
  47.             {
  48.                 string[] temp = GetString().Split(':');
  49.                 if (temp[0] == "IM")
  50.                 {
  51.  
  52.                 }
  53.                 else if (temp[0] == "Group")
  54.                 {
  55.  
  56.                 }
  57.                 else if (temp[0] == "Register")
  58.                 {
  59.                     if (ZDB.CreateUser(new UserDB(temp[1], temp[2], temp[3], temp[4], temp[5], 0)) == 1)
  60.                     {
  61.                         string New = "test";
  62.                     }
  63.  
  64.                 }
  65.                 else if (temp[0] == "Local")
  66.                 {
  67.  
  68.                 }
  69.                 else if (temp[0] == "Login")
  70.                 {
  71.                     if (ZDB.GetUser(temp[1], temp[2]).Username != "")
  72.                     {
  73.                         SW.WriteLine("Logged In!");
  74.                         SW.Flush();
  75.                         SW.WriteLine("Characters," + ZDB.GetCountCharacters());
  76.                     }
  77.                     else
  78.                     {
  79.                         SW.WriteLine("Username/Password/Wrong");
  80.                         SW.Flush();
  81.                         Connected = false;
  82.                         TcpClient.Close();
  83.                         TcpListener.Stop();
  84.                     }
  85.                 }
  86.                 else if (temp[0] == "Logout")
  87.                 {
  88.                     Connected = false;
  89.                     Username = "";
  90.                     Password = "";
  91.                     if (ZDB.GetUser(temp[1], temp[2]).Username != "")
  92.                     {
  93.                         SW.WriteLine("Logged out!");
  94.                         SW.Flush();
  95.                         TcpClient.Close();
  96.                         TcpListener.Stop();
  97.                         //SW.WriteLine("Characters," + ZDB.GetCountCharacters());
  98.                     }
  99.                     else
  100.                     {
  101.                         SW.WriteLine("Username/Password/Wrong");
  102.                         SW.Flush();
  103.                         TcpClient.Close();
  104.                         TcpListener.Stop();
  105.                     }
  106.                 }
  107.             }
  108.         }
  109.         public string GetString()
  110.         {
  111.             return SR.ReadLine();
  112.         }
  113.         public string GetPlayersInRange()
  114.         {
  115.             return "";
  116.         }
  117.         public void NewThread(object obj)
  118.         {
  119.             TcpListener = new TcpListener(IPAddress.Parse(ipaddress), port);
  120.             TcpListener.Start();
  121.             int i = 0;
  122.             while (true)
  123.             {
  124.                 if (i == 0)
  125.                 {
  126.                     this.TcpClient = this.TcpListener.AcceptTcpClient();
  127.                     T.Elapsed += new System.Timers.ElapsedEventHandler(T_Elapsed);
  128.                     T.Start();
  129.                     SW = new System.IO.StreamWriter(TcpClient.GetStream());
  130.                     SR = new System.IO.StreamReader(TcpClient.GetStream());
  131.                     SW.WriteLine("Connected");
  132.                     SW.Flush();
  133.                 }
  134.                 i++;
  135.             }
  136.         }
  137.  
  138.         public void send(byte[] Data)
  139.         {
  140.             Send = true;
  141.         }
  142.         public void CheckPlayerMatrix(byte[] Data)
  143.         {
  144.  
  145.         }
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement