Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Net.Sockets;
- using System.Threading;
- using System.Runtime.InteropServices;
- namespace teamwork_api.WinAuth
- {
- class Auth
- {
- public List<string> Users { get; set; }
- public Dictionary<string, string> Admins { get; set; }
- public Auth(List<string> users, Dictionary<string, string> admins)
- {
- Users = users;
- Admins = admins;
- }
- private string GetStringWOBlankLines(byte[] buffer)
- {
- for (int i = 0; i < buffer.Length; i++)
- {
- if (buffer[i] == 0x00)
- {
- buffer[i] = 0x90;
- }
- }
- return ASCIIEncoding.ASCII.GetString(buffer).Replace("?", String.Empty);
- }
- private void TransferClient([Out()] WinClient cl, WinClient cl2)
- {
- cl = cl2;
- }
- private WinClient GetWinClient(TcpListener lis)
- {
- if (lis.Pending())
- {
- return new WinClient(lis.AcceptTcpClient(), "locahost");
- }
- return null;
- }
- private void xListen()
- {
- TcpListener lis = new TcpListener(6005);
- lis.Start();
- while (true)
- {
- if (lis.Pending())
- {
- TcpClient client = lis.AcceptTcpClient();
- WinClient winCl = new WinClient(client, "localhost");
- if (client.Connected)
- {
- string arguments = "";
- using (Stream s = client.GetStream())
- {
- byte[] b = new byte[300];
- s.Read(b, 0, b.Length);
- arguments = GetStringWOBlankLines(b);
- }
- if (arguments.StartsWith("/login")) //unless but we have to make sure that we aren't recieving any other commands.
- {
- string user = arguments.Replace("/login ", "").Split(',')[0];
- string password = arguments.Replace("/login ", "").Split(',')[1];
- if (Admins.ContainsKey(user) && Admins.ContainsValue(password))
- {
- //Transfer the Client to the server
- //client.Connect("localhost", 10225);
- winCl.Transfer(10225);
- TransferClient(GetWinClient(lis), winCl);
- }
- else
- {
- if (Users.Contains(user))
- {
- //Transfer the Client to the server
- //client.Connect("localhost", 10225);
- winCl.Transfer(10225);
- TransferClient(GetWinClient(lis), winCl);
- }
- else
- {
- //Refuse any type of connections from this client
- //client.Close();
- winCl.Client.Close();
- TransferClient(GetWinClient(lis), winCl);
- }
- }
- }
- }
- }
- }
- }
- public void Run()
- {
- Thread thr = new Thread(new ThreadStart(xListen));
- thr.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement