Files
GameServer/MistoxServer/Interface/Interface.cs
T

34 lines
1.2 KiB
C#

using System;
using System.Net;
using Mistox.Attributes;
namespace Mistox {
public class mServer {
public static ServerInterface newServer( string serverName, int port ) {
NetworkPacketDictionary.BuildNetworkPacketList();
return new ServerInterface(port, serverName);
}
public static ClientInterface newClient( string ServerIPOrHostName, int Port ) {
NetworkPacketDictionary.BuildNetworkPacketList();
int index = 0;
IPAddress[] remoteAddress = Dns.GetHostAddresses(ServerIPOrHostName);
for( int i=0; i< remoteAddress.Length; i++ ) {
if( remoteAddress[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork || remoteAddress [i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 ) {
index = i;
}
}
string ipAddress = remoteAddress[index].ToString();
if ( remoteAddress.Length > 0) {
return new ClientInterface(ipAddress, Port);
} else {
Console.WriteLine("The server at " + ServerIPOrHostName + " doesn't exit or cannot be found");
return null;
}
}
}
}