贺州人民医院电子沙盘
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

72 lines
1.9 KiB

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Net;
/// <summary>
/// 表示游戏设置。
/// </summary>
public static class GameSetting
{
/// <summary>
/// 表示登录服务器的设置。
/// </summary>
public static readonly LoginSetting LoginSetting = new LoginSetting();
}
/// <summary>
/// 表示登录服务器的设置。
/// </summary>
public class LoginSetting
{
private List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();
/// <summary>
/// 随机获取一个登录服务器地址。
/// </summary>
public bool GetLoginAddress(out string ip, out int port)
{
var index = Random.Range(0, list.Count);
ip = list[index].Key;
port = list[index].Value;
return true;
}
/// <summary>
/// 随机获取一个登录服务器地址。
/// </summary>
public IPEndPoint GetLoginAddress()
{
string ip;
int port;
GetLoginAddress(out ip, out port);
return new IPEndPoint(IPAddress.Parse(ip), port);
}
/// <summary>
/// 设置登录服务器地址。
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
public void SetLoginAddress(string ip, int port)
{
list.Add(new KeyValuePair<string, int>(ip, port));
}
/// <summary>
/// 表示指定的地址是否包含在登录服务器设置中,即该地址是否是登录服务器地址。
/// </summary>
public bool Contains(IPEndPoint endpoint)
{
return Contains(endpoint.Address.ToString(), (int)endpoint.Port);
}
/// <summary>
/// 表示指定的地址是否包含在登录服务器设置中,即该地址是否是登录服务器地址。
/// </summary>
public bool Contains(string ip, int port)
{
return list.Exists((pair) => ip == pair.Key && port == pair.Value);
}
}