Mud Designer UI:
- Began support work on the networking side of the designer UI. Attempts to connect to the server or run stand-alone. - Began implementing object creation. Mud Engine: - Added the [Browsable(false)] attribute to several Game properties so they are not visible within the new Designer.
This commit is contained in:
parent
a347607337
commit
f446c754fb
9 changed files with 556 additions and 56 deletions
96
MudDesigner/Client.cs
Normal file
96
MudDesigner/Client.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace MudDesigner
|
||||
{
|
||||
public class Client
|
||||
{
|
||||
public Client()
|
||||
{
|
||||
}
|
||||
~Client()
|
||||
{
|
||||
}
|
||||
public Boolean Initialize(string i, int p)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (i.Length <= 0)
|
||||
return false;
|
||||
ip = i;
|
||||
if (p <= 0)
|
||||
return false;
|
||||
port = p;
|
||||
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public Boolean Connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
sock.Connect(ip, port);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public Boolean Send(string data,Boolean newLine)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||
if(newLine)
|
||||
data += "\n";
|
||||
sock.Send(encoding.GetBytes(data));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public Boolean Receive(out string rs,int size)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] data = new byte[size];
|
||||
sock.Receive(data);
|
||||
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
|
||||
rs = enc.GetString(data.ToArray());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
rs = "";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public Boolean End()
|
||||
{
|
||||
try
|
||||
{
|
||||
sock.Close();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private string ip;
|
||||
private int port;
|
||||
|
||||
private Socket sock;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue