Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- namespace GL_Zombie_Server
- {
- public class NetworkClient
- {
- public string Username = "";
- public string Password = "";
- public bool Connected = true;
- System.IO.StreamReader SR;
- System.IO.StreamWriter SW;
- //public event ReadyToReconnect Recieved;
- public int Number;
- bool Send = false;
- public byte[] Buffer;
- System.Net.Sockets.TcpListener TcpListener;
- System.Net.Sockets.TcpClient TcpClient;
- ZombieDB ZDB = new ZombieDB();
- System.Threading.Thread Thread;
- System.Timers.Timer T = new System.Timers.Timer(175);
- string ipaddress;
- int port;
- public NetworkClient(string ipaddress, int port)//, string Username, string Password)
- {
- this.ipaddress = ipaddress;
- this.port = port;
- /*this.Username = Username;
- this.Password = Password;*/
- //PTS += new System.Threading.ParameterizedThreadStart(NewThread);
- Thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(NewThread));
- Thread.Start();
- }
- public void SendData(string Data)
- {
- SW.Write(Data);
- SW.Flush();
- }
- void T_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- while (TcpClient.GetStream().DataAvailable)
- {
- string[] temp = GetString().Split(':');
- if (temp[0] == "IM")
- {
- }
- else if (temp[0] == "Group")
- {
- }
- else if (temp[0] == "Register")
- {
- if (ZDB.CreateUser(new UserDB(temp[1], temp[2], temp[3], temp[4], temp[5], 0)) == 1)
- {
- string New = "test";
- }
- }
- else if (temp[0] == "Local")
- {
- }
- else if (temp[0] == "Login")
- {
- if (ZDB.GetUser(temp[1], temp[2]).Username != "")
- {
- SW.WriteLine("Logged In!");
- SW.Flush();
- SW.WriteLine("Characters," + ZDB.GetCountCharacters());
- }
- else
- {
- SW.WriteLine("Username/Password/Wrong");
- SW.Flush();
- Connected = false;
- TcpClient.Close();
- TcpListener.Stop();
- }
- }
- else if (temp[0] == "Logout")
- {
- Connected = false;
- Username = "";
- Password = "";
- if (ZDB.GetUser(temp[1], temp[2]).Username != "")
- {
- SW.WriteLine("Logged out!");
- SW.Flush();
- TcpClient.Close();
- TcpListener.Stop();
- //SW.WriteLine("Characters," + ZDB.GetCountCharacters());
- }
- else
- {
- SW.WriteLine("Username/Password/Wrong");
- SW.Flush();
- TcpClient.Close();
- TcpListener.Stop();
- }
- }
- }
- }
- public string GetString()
- {
- return SR.ReadLine();
- }
- public string GetPlayersInRange()
- {
- return "";
- }
- public void NewThread(object obj)
- {
- TcpListener = new TcpListener(IPAddress.Parse(ipaddress), port);
- TcpListener.Start();
- int i = 0;
- while (true)
- {
- if (i == 0)
- {
- this.TcpClient = this.TcpListener.AcceptTcpClient();
- T.Elapsed += new System.Timers.ElapsedEventHandler(T_Elapsed);
- T.Start();
- SW = new System.IO.StreamWriter(TcpClient.GetStream());
- SR = new System.IO.StreamReader(TcpClient.GetStream());
- SW.WriteLine("Connected");
- SW.Flush();
- }
- i++;
- }
- }
- public void send(byte[] Data)
- {
- Send = true;
- }
- public void CheckPlayerMatrix(byte[] Data)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement