Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text;
- using System.Net.Sockets;
- using UnityEngine;
- using System.Threading;
- using MySql.Data.MySqlClient;
- using System.Data;
- namespace Server
- {
- public class SocketHelper : MonoBehaviour
- {
- TcpClient mscClient;
- string mstrMessage;
- string mstrResponse;
- byte[] bytesSent;
- public string incomingData = null;
- byte[] data = new byte[256];
- public string MyConncetionString = "Server=localhost;Database=server;Uid=root;Pwd=;";
- public string idString = "";
- public string pwString = "";
- private string passwordData;
- public void processData(TcpClient client, NetworkStream stream, byte[] bytesReceived)
- {
- Debug.Log(Thread.CurrentThread.Name);
- while (true)
- {
- int bytes = stream.Read(data, 0, data.Length);
- incomingData = Encoding.ASCII.GetString(data, 0, bytes);
- Debug.Log(incomingData);
- string[] words = incomingData.Split(' ');
- foreach (string word in words)
- {
- idString = words[0];
- Debug.Log(idString);
- pwString = words[1];
- Debug.Log(pwString);
- }
- Thread AuthServer = new Thread(authServer);
- AuthServer.Name = "AuthorisationThread";
- AuthServer.Start();
- }
- }
- public void authServer()
- {
- MySqlConnection connection = null;
- string hostname = "localhost";
- string database = "server";
- string username = "root";
- string password = "";
- connection = new MySqlConnection("host=" + hostname +
- ";database=" + database +
- ";username=" + username +
- ";password=" + password + ";");
- MySqlCommand cmd;
- connection.Open();
- Debug.Log("MySQL Connection established");
- DataSet ds = new DataSet();
- cmd = connection.CreateCommand();
- cmd.CommandText = "select * from account " +
- "where login like '" + idString + "'";
- MySqlDataReader reader = cmd.ExecuteReader();
- reader.Read();
- passwordData = reader.GetString("password");
- if (passwordData == pwString)
- {
- Debug.Log("logged in");
- WorldServer worldServer = new WorldServer();
- Thread account = new Thread(() => worldServer.Account(idString));
- account.Name = idString;
- Debug.Log(account.Name.ToString());
- account.Start();
- Server server = new Server();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement