Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Net;
- using System.Net.Sockets;
- namespace Game
- {
- public partial class Form1 : Form
- {
- delegate LoginSocket LogInDelegate(Spine.Objects.loginpackage l);
- Socket client;
- IPAddress[] aryLocalAddr = null;
- int serverport = 1000;
- int backlog = 20;
- Spine.Objects O = new Spine.Objects();
- BackgroundWorker Login = new BackgroundWorker();
- [Serializable]
- public class LoginSocket{
- public Spine.Objects.Player P = new Spine.Objects.Player();
- public Spine.Objects.logininfo L;
- public string username;
- public string password;
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- Socket listener = new Socket(AddressFamily.InterNetwork,
- SocketType.Stream, ProtocolType.Tcp);
- IPAddress hostIP = (Dns.Resolve(IPAddress.Any.ToString())).AddressList[0];
- listener.Bind(new IPEndPoint(hostIP, serverport));
- //listener.Bind( new IPEndPoint( IPAddress.Loopback, 399 ) );
- // For use with localhost 127.0.0.1
- listener.Listen(10);
- // Setup a callback to be notified of connection requests
- listener.BeginAccept(new AsyncCallback(OnConnectRequest), listener);
- }
- public void OnConnectRequest(IAsyncResult ar)
- {
- string response = "";
- Socket listener = (Socket)ar.AsyncState;
- client = listener.EndAccept(ar);
- byte [] b = new byte[1024];
- int bytes = 0;
- do
- {
- bytes = client.Receive(b);
- response += Encoding.ASCII.GetString(b, 0, bytes);
- } while (bytes > 0 && !response.Contains("\r\n"));
- string requesttype = response.Substring(0, 1);
- string objectrep = response.Substring(1).Replace("\r\n", "");
- object O = Spine.Objects.ByteArrayToObject(System.Text.Encoding.ASCII.GetBytes(objectrep));
- Spine.Objects.loginpackage LP;
- if (requesttype == "L")
- {
- LP = (Spine.Objects.loginpackage)O;
- LogInDelegate d = new LogInDelegate(logInDelegate);
- object o = this.Invoke (d, new object[] { LP });
- LoginSocket LS = (LoginSocket)o;
- client.Send(Spine.Objects.BuildRequest(LS,"L"));
- }
- listener.BeginAccept(new AsyncCallback(OnConnectRequest), listener);
- // It's on a different thread, so use Invoke.
- }
- private LoginSocket logInDelegate(Spine.Objects.loginpackage l)
- {
- LoginSocket L = new LoginSocket();
- Spine.Objects.Player P = O.login(l);
- L.P = P;
- L.password = l.password;
- L.username = l.username;
- L.L = new Spine.Objects.logininfo(P.Session, P.Info.ID);
- O.PlayerBuffer.Add(P);
- return L;
- }
- private void Click_Tick(object sender, EventArgs e)
- {
- if (O.PlayerBuffer.Count > 0)
- {
- string s = "s";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement