forked from project-redbud/FunGame-Core
调试checklogin
This commit is contained in:
parent
35a060f693
commit
db9437ada6
@ -17,33 +17,33 @@ namespace FunGame.Core.Api.Model.Enum
|
|||||||
|
|
||||||
public enum StartMatch_State
|
public enum StartMatch_State
|
||||||
{
|
{
|
||||||
Matching = 1,
|
Matching,
|
||||||
Success = 2,
|
Success,
|
||||||
Enable = 3,
|
Enable,
|
||||||
Cancel = 4
|
Cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CreateRoom_State
|
public enum CreateRoom_State
|
||||||
{
|
{
|
||||||
Creating = 1,
|
Creating,
|
||||||
Success = 2
|
Success
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum RoomState
|
public enum RoomState
|
||||||
{
|
{
|
||||||
Created = 1,
|
Created,
|
||||||
Gaming = 2,
|
Gaming,
|
||||||
Close = 3,
|
Close,
|
||||||
Complete = 4
|
Complete
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum OnlineState
|
public enum OnlineState
|
||||||
{
|
{
|
||||||
Offline = 1,
|
Offline,
|
||||||
Online = 2,
|
Online,
|
||||||
Matching = 3,
|
Matching,
|
||||||
InRoom = 4,
|
InRoom,
|
||||||
Gaming = 5
|
Gaming
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -52,33 +52,33 @@ namespace FunGame.Core.Api.Model.Enum
|
|||||||
|
|
||||||
public enum RoomType
|
public enum RoomType
|
||||||
{
|
{
|
||||||
Mix = 1,
|
Mix,
|
||||||
Team = 2,
|
Team,
|
||||||
MixHasPass = 3,
|
MixHasPass,
|
||||||
TeamHasPass = 4
|
TeamHasPass
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum InterfaceType
|
public enum InterfaceType
|
||||||
{
|
{
|
||||||
ClientConnectInterface = 1,
|
ClientConnectInterface,
|
||||||
ServerInterface = 2
|
ServerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LightType
|
public enum LightType
|
||||||
{
|
{
|
||||||
Green = 1,
|
Green,
|
||||||
Yellow = 2,
|
Yellow,
|
||||||
Red = 3
|
Red
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SocketType
|
public enum SocketType
|
||||||
{
|
{
|
||||||
Unknown = 0,
|
Unknown,
|
||||||
GetNotice = 1,
|
GetNotice,
|
||||||
Login = 2,
|
Login,
|
||||||
CheckLogin = 3,
|
CheckLogin,
|
||||||
Logout = 4,
|
Logout,
|
||||||
HeartBeat = 5
|
HeartBeat
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -87,11 +87,11 @@ namespace FunGame.Core.Api.Model.Enum
|
|||||||
|
|
||||||
public enum MessageResult
|
public enum MessageResult
|
||||||
{
|
{
|
||||||
OK = 1,
|
OK,
|
||||||
Cancel = 2,
|
Cancel,
|
||||||
Yes = 3,
|
Yes,
|
||||||
No = 4,
|
No,
|
||||||
Retry = 5
|
Retry
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -100,16 +100,17 @@ namespace FunGame.Core.Api.Model.Enum
|
|||||||
|
|
||||||
public enum WebHelperMethod
|
public enum WebHelperMethod
|
||||||
{
|
{
|
||||||
CreateSocket = 1,
|
CreateSocket,
|
||||||
CloseSocket = 2,
|
CloseSocket,
|
||||||
StartWebHelper = 3,
|
StartWebHelper,
|
||||||
|
Login
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum InterfaceMethod
|
public enum InterfaceMethod
|
||||||
{
|
{
|
||||||
RemoteServerIP = 1,
|
RemoteServerIP,
|
||||||
DBConnection = 2,
|
DBConnection,
|
||||||
GetServerSettings = 3
|
GetServerSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -6,39 +6,41 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace FunGame.Core.Api.Model.Enum
|
namespace FunGame.Core.Api.Model.Enum
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 用于记录版本号和更新日志
|
|
||||||
/// </summary>
|
|
||||||
public static class FunGameEnums
|
public static class FunGameEnums
|
||||||
{
|
{
|
||||||
public const string FunGame_Core = "FunGame Core";
|
private const string FunGame_Core = "FunGame Core";
|
||||||
public const string FunGame_Core_Api = "FunGame Core Api";
|
private const string FunGame_Core_Api = "FunGame Core Api";
|
||||||
public const string FunGame_Console = "FunGame Console";
|
private const string FunGame_Console = "FunGame Console";
|
||||||
public const string FunGame_Desktop = "FunGame Desktop";
|
private const string FunGame_Desktop = "FunGame Desktop";
|
||||||
public const string FunGame_Server = "FunGame Server";
|
private const string FunGame_Server = "FunGame Server Console";
|
||||||
|
|
||||||
public const int FirstVersion = 1;
|
private const string FunGame_Version = "v1.0";
|
||||||
public const int SecondVersion = 0;
|
private const string FunGame_VersionPatch = "";
|
||||||
public const int ThirdVersion = 0;
|
|
||||||
|
|
||||||
public enum Patch
|
public enum FunGame
|
||||||
{
|
{
|
||||||
Latest = 20221001,
|
FunGame_Core,
|
||||||
Patch20220906 = 20220906
|
FunGame_Core_Api,
|
||||||
|
FunGame_Console,
|
||||||
|
FunGame_Desktop,
|
||||||
|
FunGame_Server
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum History
|
public static string GetInfo(FunGame FunGameType)
|
||||||
{
|
{
|
||||||
Latest = 20221001,
|
string type = FunGameType switch
|
||||||
R20220906 = 20220906
|
{
|
||||||
}
|
FunGame.FunGame_Core => FunGame_Core,
|
||||||
|
FunGame.FunGame_Core_Api => FunGame_Core_Api,
|
||||||
public static string GetVersion()
|
FunGame.FunGame_Console => FunGame_Console,
|
||||||
{
|
FunGame.FunGame_Desktop => FunGame_Desktop,
|
||||||
return "=/=\\=/=\\=/=\\=/= > FunGame版本信息 < =\\=/=\\=/=\\=/=\\=" + "\n" +
|
FunGame.FunGame_Server => FunGame_Server,
|
||||||
FunGame_Core + " -> v" + FirstVersion + "." + SecondVersion + ((int)Patch.Latest == (int)History.Latest ? " Patch" + (int)Patch.Latest : "") + "\n" +
|
_ => ""
|
||||||
FunGame_Core_Api + " -> v" + FirstVersion + "." + SecondVersion + ((int)Patch.Latest == (int)History.Latest ? " Patch" + (int)Patch.Latest : "") + "\n" +
|
};
|
||||||
FunGame_Desktop + " -> v" + FirstVersion + "." + SecondVersion + ((int)Patch.Latest == (int)History.Latest ? " Patch" + (int)Patch.Latest : "");
|
if (type.Equals(FunGame_Desktop))
|
||||||
|
return type + " [ 版本: " + FunGame_Version + FunGame_VersionPatch + " ]\n©2022 Mili.cyou. 保留所有权利\n";
|
||||||
|
else
|
||||||
|
return type + " [ 版本: " + FunGame_Version + FunGame_VersionPatch + " ]\n(C)2022 Mili.cyou. 保留所有权利\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using FunGame.Core.Api.Model.Enum;
|
||||||
using FunGame.Core.Api.Util;
|
using FunGame.Core.Api.Util;
|
||||||
|
|
||||||
namespace FunGame.Desktop.Models.Config
|
namespace FunGame.Desktop.Models.Config
|
||||||
@ -13,10 +14,7 @@ namespace FunGame.Desktop.Models.Config
|
|||||||
/**
|
/**
|
||||||
* Game Configs
|
* Game Configs
|
||||||
*/
|
*/
|
||||||
public static string VERSION = "";
|
public static FunGameEnums.FunGame FunGameType = FunGameEnums.FunGame.FunGame_Desktop;
|
||||||
public static string VERSION_TYPE = "";
|
|
||||||
public static string VERSION_PATCH = "";
|
|
||||||
public static string VERSION_DATE = "";
|
|
||||||
|
|
||||||
public static INIHelper DefaultINIHelper = new();
|
public static INIHelper DefaultINIHelper = new();
|
||||||
public static AssemblyHelper DefaultAssemblyHelper = new();
|
public static AssemblyHelper DefaultAssemblyHelper = new();
|
||||||
@ -30,6 +28,7 @@ namespace FunGame.Desktop.Models.Config
|
|||||||
public const string WebHelper_SetYellow = "-WebHelper .set yellow";
|
public const string WebHelper_SetYellow = "-WebHelper .set yellow";
|
||||||
public const string WebHelper_Disconnected = "-WebHelper .disconnected";
|
public const string WebHelper_Disconnected = "-WebHelper .disconnected";
|
||||||
public const string WebHelper_GetUser = "-WebHelper .get user";
|
public const string WebHelper_GetUser = "-WebHelper .get user";
|
||||||
|
public const string WebHelper_SetUser = "-WebHelper .set user";
|
||||||
public static int WebHelper_HeartBeatFaileds = 0;
|
public static int WebHelper_HeartBeatFaileds = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,7 +57,7 @@ namespace FunGame.Desktop.Models.Config
|
|||||||
public const string FunGame_Retry = "重新连接";
|
public const string FunGame_Retry = "重新连接";
|
||||||
public const string FunGame_AutoRetryOn = "开启自动重连";
|
public const string FunGame_AutoRetryOn = "开启自动重连";
|
||||||
public const string FunGame_AutoRetryOff = "关闭自动重连";
|
public const string FunGame_AutoRetryOff = "关闭自动重连";
|
||||||
public static readonly object[] PresetItems =
|
public static readonly object[] PresetOnineItems =
|
||||||
{
|
{
|
||||||
FunGame_PresetMessage,
|
FunGame_PresetMessage,
|
||||||
FunGame_SignIn,
|
FunGame_SignIn,
|
||||||
@ -72,6 +71,12 @@ namespace FunGame.Desktop.Models.Config
|
|||||||
FunGame_AutoRetryOn,
|
FunGame_AutoRetryOn,
|
||||||
FunGame_AutoRetryOff
|
FunGame_AutoRetryOff
|
||||||
};
|
};
|
||||||
public const string FunGame_ConnectByDebug = "连接到Debug";
|
public static readonly object[] PresetNoLoginItems =
|
||||||
|
{
|
||||||
|
FunGame_PresetMessage,
|
||||||
|
FunGame_Retry,
|
||||||
|
FunGame_AutoRetryOn,
|
||||||
|
FunGame_AutoRetryOff
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using FunGame.Core.Api.Model.Entity;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -11,6 +12,8 @@ namespace FunGame.Desktop.Models.Config
|
|||||||
/**
|
/**
|
||||||
* 玩家设定内容
|
* 玩家设定内容
|
||||||
*/
|
*/
|
||||||
|
public static User? LoginUser = null; // 已登录的用户
|
||||||
|
public static string LoginUserName = ""; // 已登录用户名
|
||||||
public static bool Match_Mix = false; // 混战模式选项
|
public static bool Match_Mix = false; // 混战模式选项
|
||||||
public static bool Match_Team = false; // 团队模式选项
|
public static bool Match_Team = false; // 团队模式选项
|
||||||
public static bool Match_HasPass = false; // 密码房间选项
|
public static bool Match_HasPass = false; // 密码房间选项
|
||||||
@ -19,6 +22,5 @@ namespace FunGame.Desktop.Models.Config
|
|||||||
public static bool FunGame_isRetrying = false; // 是否正在重连
|
public static bool FunGame_isRetrying = false; // 是否正在重连
|
||||||
public static bool FunGame_isAutoRetry = true; // 是否自动重连
|
public static bool FunGame_isAutoRetry = true; // 是否自动重连
|
||||||
public static string FunGame_roomid = "-1"; // 房间号
|
public static string FunGame_roomid = "-1"; // 房间号
|
||||||
public static string LoginUserName = ""; // 已登录用户名
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,6 @@ namespace FunGame.Desktop.UI
|
|||||||
* 定义全局对象
|
* 定义全局对象
|
||||||
*/
|
*/
|
||||||
private Task? MatchFunGame = null; // 匹配线程
|
private Task? MatchFunGame = null; // 匹配线程
|
||||||
private User? LoginUser = null; // 登录的玩家对象
|
|
||||||
private WebHelper? WebHelper = null; // WebHelper
|
private WebHelper? WebHelper = null; // WebHelper
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,7 +51,7 @@ namespace FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
this.PresetText.SelectedIndex = 0; // 快捷消息初始选择
|
SetButtonEnableIfLogon(false);
|
||||||
SetRoomid("-1"); // 房间号初始化
|
SetRoomid("-1"); // 房间号初始化
|
||||||
ShowFunGameInfo(); // 显示FunGame信息
|
ShowFunGameInfo(); // 显示FunGame信息
|
||||||
GetServerConnection(); // 开始连接服务器
|
GetServerConnection(); // 开始连接服务器
|
||||||
@ -69,7 +68,7 @@ namespace FunGame.Desktop.UI
|
|||||||
/// <param name="msg"></param>
|
/// <param name="msg"></param>
|
||||||
/// <param name="needTime"></param>
|
/// <param name="needTime"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public object? GetMessage(WebHelper webHelper, string? msg, bool needTime = false)
|
public object? GetMessage(WebHelper webHelper, string? msg, bool needTime = false, object[]? objs = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -82,6 +81,7 @@ namespace FunGame.Desktop.UI
|
|||||||
WebHelper_Action = (main) =>
|
WebHelper_Action = (main) =>
|
||||||
{
|
{
|
||||||
SetServerStatusLight((int)CommonEnums.LightType.Green);
|
SetServerStatusLight((int)CommonEnums.LightType.Green);
|
||||||
|
SetButtonEnableIfLogon(true);
|
||||||
};
|
};
|
||||||
if (InvokeRequired)
|
if (InvokeRequired)
|
||||||
BeginInvoke(WebHelper_Action, this);
|
BeginInvoke(WebHelper_Action, this);
|
||||||
@ -95,6 +95,7 @@ namespace FunGame.Desktop.UI
|
|||||||
WebHelper_Action = (main) =>
|
WebHelper_Action = (main) =>
|
||||||
{
|
{
|
||||||
SetServerStatusLight((int)CommonEnums.LightType.Green, GetServerPing(Config.SERVER_IPADRESS));
|
SetServerStatusLight((int)CommonEnums.LightType.Green, GetServerPing(Config.SERVER_IPADRESS));
|
||||||
|
SetButtonEnableIfLogon(true);
|
||||||
};
|
};
|
||||||
if (InvokeRequired)
|
if (InvokeRequired)
|
||||||
BeginInvoke(WebHelper_Action, this);
|
BeginInvoke(WebHelper_Action, this);
|
||||||
@ -108,6 +109,7 @@ namespace FunGame.Desktop.UI
|
|||||||
WebHelper_Action = (main) =>
|
WebHelper_Action = (main) =>
|
||||||
{
|
{
|
||||||
SetServerStatusLight((int)CommonEnums.LightType.Yellow);
|
SetServerStatusLight((int)CommonEnums.LightType.Yellow);
|
||||||
|
SetButtonEnableIfLogon(false);
|
||||||
};
|
};
|
||||||
if (InvokeRequired)
|
if (InvokeRequired)
|
||||||
BeginInvoke(WebHelper_Action, this);
|
BeginInvoke(WebHelper_Action, this);
|
||||||
@ -120,6 +122,7 @@ namespace FunGame.Desktop.UI
|
|||||||
WebHelper_Action = (main) =>
|
WebHelper_Action = (main) =>
|
||||||
{
|
{
|
||||||
SetServerStatusLight((int)CommonEnums.LightType.Red);
|
SetServerStatusLight((int)CommonEnums.LightType.Red);
|
||||||
|
SetButtonEnableIfLogon(false);
|
||||||
};
|
};
|
||||||
if (InvokeRequired)
|
if (InvokeRequired)
|
||||||
BeginInvoke(WebHelper_Action, this);
|
BeginInvoke(WebHelper_Action, this);
|
||||||
@ -132,6 +135,7 @@ namespace FunGame.Desktop.UI
|
|||||||
WebHelper_Action = (main) =>
|
WebHelper_Action = (main) =>
|
||||||
{
|
{
|
||||||
SetServerStatusLight((int)CommonEnums.LightType.Red);
|
SetServerStatusLight((int)CommonEnums.LightType.Red);
|
||||||
|
SetButtonEnableIfLogon(false);
|
||||||
};
|
};
|
||||||
if (InvokeRequired)
|
if (InvokeRequired)
|
||||||
BeginInvoke(WebHelper_Action, this);
|
BeginInvoke(WebHelper_Action, this);
|
||||||
@ -156,8 +160,17 @@ namespace FunGame.Desktop.UI
|
|||||||
else
|
else
|
||||||
throw new Exception("ERROR:无法连接至服务器,请检查你的网络连接。");
|
throw new Exception("ERROR:无法连接至服务器,请检查你的网络连接。");
|
||||||
case Config.WebHelper_GetUser:
|
case Config.WebHelper_GetUser:
|
||||||
if (LoginUser != null)
|
if (Usercfg.LoginUser != null)
|
||||||
return LoginUser;
|
return Usercfg.LoginUser;
|
||||||
|
return null;
|
||||||
|
case Config.WebHelper_SetUser:
|
||||||
|
if (objs != null && objs.Length > 1)
|
||||||
|
{
|
||||||
|
if (InvokeRequired)
|
||||||
|
BeginInvoke(SetLoginUser, objs);
|
||||||
|
else
|
||||||
|
SetLoginUser(objs);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
default:
|
default:
|
||||||
if (needTime)
|
if (needTime)
|
||||||
@ -307,12 +320,10 @@ namespace FunGame.Desktop.UI
|
|||||||
/// <param name="objs"></param>
|
/// <param name="objs"></param>
|
||||||
private void SetLoginUser(object[]? objs = null)
|
private void SetLoginUser(object[]? objs = null)
|
||||||
{
|
{
|
||||||
if (objs != null && objs.Length > 0)
|
if (InvokeRequired)
|
||||||
{
|
BeginInvoke(LoginAccount, objs);
|
||||||
LoginUser = (User)objs[0];
|
else
|
||||||
Usercfg.LoginUserName = LoginUser.Userame;
|
LoginAccount(objs);
|
||||||
}
|
|
||||||
LoginAccount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -400,6 +411,33 @@ namespace FunGame.Desktop.UI
|
|||||||
RoomSetting.Visible = true;
|
RoomSetting.Visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 未登录和离线时,停用按钮
|
||||||
|
/// </summary>
|
||||||
|
private void SetButtonEnableIfLogon(bool isLogon)
|
||||||
|
{
|
||||||
|
if (isLogon)
|
||||||
|
{
|
||||||
|
PresetText.Items.Clear();
|
||||||
|
PresetText.Items.AddRange(Config.PresetOnineItems);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PresetText.Items.Clear();
|
||||||
|
PresetText.Items.AddRange(Config.PresetNoLoginItems);
|
||||||
|
}
|
||||||
|
this.PresetText.SelectedIndex = 0;
|
||||||
|
CheckMix.Enabled = isLogon;
|
||||||
|
CheckTeam.Enabled = isLogon;
|
||||||
|
CheckHasPass.Enabled = isLogon;
|
||||||
|
StartMatch.Enabled = isLogon;
|
||||||
|
CreateRoom.Enabled = isLogon;
|
||||||
|
RoomBox.Enabled = isLogon;
|
||||||
|
AccountSetting.Enabled = isLogon;
|
||||||
|
Stock.Enabled = isLogon;
|
||||||
|
Store.Enabled = isLogon;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加入房间
|
/// 加入房间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -572,11 +610,18 @@ namespace FunGame.Desktop.UI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 登录账号,显示登出按钮
|
/// 登录账号,显示登出按钮
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void LoginAccount()
|
private void LoginAccount(object[]? objs = null)
|
||||||
{
|
{
|
||||||
|
if (objs != null && objs.Length > 0)
|
||||||
|
{
|
||||||
|
Usercfg.LoginUser = (User)objs[2];
|
||||||
|
Usercfg.LoginUserName = Usercfg.LoginUser.Userame;
|
||||||
|
}
|
||||||
NowAccount.Text = "[ID] " + Usercfg.LoginUserName;
|
NowAccount.Text = "[ID] " + Usercfg.LoginUserName;
|
||||||
Login.Visible = false;
|
Login.Visible = false;
|
||||||
Logout.Visible = true;
|
Logout.Visible = true;
|
||||||
|
SetServerStatusLight((int)LightType.Green);
|
||||||
|
ShowMessage.TipMessage("欢迎回来, " + Usercfg.LoginUserName + "!", "登录成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -617,7 +662,7 @@ namespace FunGame.Desktop.UI
|
|||||||
// 向消息队列发送消息
|
// 向消息队列发送消息
|
||||||
if (!TalkText.Text.Trim().Equals("") && !TalkText.ForeColor.Equals(Color.DarkGray))
|
if (!TalkText.Text.Trim().Equals("") && !TalkText.ForeColor.Equals(Color.DarkGray))
|
||||||
{
|
{
|
||||||
WritelnGameInfo(GetNowShortTime() + " [ " + Usercfg.LoginUserName + " ] 说: " + TalkText.Text);
|
WritelnGameInfo(GetNowShortTime() + " [ " + (!Usercfg.LoginUserName.Equals("") ? Usercfg.LoginUserName : "尚未登录") + " ] 说: " + TalkText.Text);
|
||||||
SwitchTalkMessage(TalkText.Text);
|
SwitchTalkMessage(TalkText.Text);
|
||||||
TalkText.Text = "";
|
TalkText.Text = "";
|
||||||
if (isLeave) TalkText_Leave(); // 回车不离开焦点
|
if (isLeave) TalkText_Leave(); // 回车不离开焦点
|
||||||
@ -636,7 +681,7 @@ namespace FunGame.Desktop.UI
|
|||||||
/// <param name="msg"></param>
|
/// <param name="msg"></param>
|
||||||
private void SendTalkText_Click(string msg)
|
private void SendTalkText_Click(string msg)
|
||||||
{
|
{
|
||||||
WritelnGameInfo(GetNowShortTime() + " [ " + Usercfg.LoginUserName + " ] 说: " + msg);
|
WritelnGameInfo(GetNowShortTime() + " [ " + (!Usercfg.LoginUserName.Equals("") ? Usercfg.LoginUserName : "尚未登录") + " ] 说: " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -736,7 +781,7 @@ namespace FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void ShowFunGameInfo()
|
private void ShowFunGameInfo()
|
||||||
{
|
{
|
||||||
WritelnGameInfo(FunGameEnums.GetVersion());
|
WritelnGameInfo(FunGameEnums.GetInfo(Config.FunGameType));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -930,7 +975,10 @@ namespace FunGame.Desktop.UI
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void Login_Click(object sender, EventArgs e)
|
private void Login_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoginAccount();
|
if (WebHelper != null)
|
||||||
|
WebHelper.WebHelpMethod((int)CommonEnums.WebHelperMethod.Login);
|
||||||
|
else
|
||||||
|
ShowMessage.WarningMessage("请先连接服务器!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -34,7 +34,7 @@ namespace FunGame.Desktop.Utils
|
|||||||
/// 选择WebHelp分支方法
|
/// 选择WebHelp分支方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="i">分支方法ID</param>
|
/// <param name="i">分支方法ID</param>
|
||||||
public void WebHelpMethod(int i)
|
public bool WebHelpMethod(int i)
|
||||||
{
|
{
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
@ -47,7 +47,16 @@ namespace FunGame.Desktop.Utils
|
|||||||
case (int)CommonEnums.WebHelperMethod.StartWebHelper:
|
case (int)CommonEnums.WebHelperMethod.StartWebHelper:
|
||||||
StartWebHelper();
|
StartWebHelper();
|
||||||
break;
|
break;
|
||||||
|
case (int)CommonEnums.WebHelperMethod.Login:
|
||||||
|
if (client != null)
|
||||||
|
{
|
||||||
|
Send((int)CommonEnums.SocketType.CheckLogin, new object[] { Main, client, new User("Mili") });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -148,6 +157,7 @@ namespace FunGame.Desktop.Utils
|
|||||||
case (int)CommonEnums.SocketType.Login:
|
case (int)CommonEnums.SocketType.Login:
|
||||||
break;
|
break;
|
||||||
case (int)CommonEnums.SocketType.CheckLogin:
|
case (int)CommonEnums.SocketType.CheckLogin:
|
||||||
|
Main.GetMessage(this, Config.WebHelper_SetUser, true, objs);
|
||||||
StartWebHelper(); // 开始创建TCP流
|
StartWebHelper(); // 开始创建TCP流
|
||||||
return true;
|
return true;
|
||||||
case (int)CommonEnums.SocketType.Logout:
|
case (int)CommonEnums.SocketType.Logout:
|
||||||
@ -198,50 +208,38 @@ namespace FunGame.Desktop.Utils
|
|||||||
if (socket != null)
|
if (socket != null)
|
||||||
{
|
{
|
||||||
string msg = "";
|
string msg = "";
|
||||||
byte[] buffer;
|
CommonEnums.SocketType type = (CommonEnums.SocketType)i;
|
||||||
int length;
|
|
||||||
// 发送消息给服务器端
|
// 发送消息给服务器端
|
||||||
switch (i)
|
switch (type)
|
||||||
{
|
{
|
||||||
case (int)CommonEnums.SocketType.GetNotice:
|
case CommonEnums.SocketType.GetNotice:
|
||||||
msg = "获取公告";
|
msg = MakeMessage(type, "获取公告");
|
||||||
buffer = new byte[2048];
|
if (Send(msg, socket) > 0)
|
||||||
buffer = Config.DEFAULT_ENCODING.GetBytes(MakeMessage((int)CommonEnums.SocketType.GetNotice, msg));
|
|
||||||
length = socket.Send(buffer);
|
|
||||||
if (length > 0)
|
|
||||||
{
|
{
|
||||||
return Read(objs);
|
return Read(objs);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
throw new Exception("ERROR:消息未送达服务器,与服务器连接可能丢失。");
|
||||||
|
case CommonEnums.SocketType.Login:
|
||||||
break;
|
break;
|
||||||
case (int)CommonEnums.SocketType.Login:
|
case CommonEnums.SocketType.CheckLogin:
|
||||||
break;
|
|
||||||
case (int)CommonEnums.SocketType.CheckLogin:
|
|
||||||
User user;
|
User user;
|
||||||
if (objs != null && objs.Length > 2)
|
if (objs != null && objs.Length > 2)
|
||||||
{
|
{
|
||||||
user = (User)objs[2];
|
user = (User)objs[2];
|
||||||
msg = user.Userame;
|
msg = MakeMessage(type, user.Userame);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Usercfg.FunGame_isAutoRetry = false;
|
Usercfg.FunGame_isAutoRetry = false;
|
||||||
throw new Exception("ERROR: 请登录账号。");
|
throw new Exception("ERROR: 请登录账号。");
|
||||||
}
|
}
|
||||||
buffer = new byte[2048];
|
|
||||||
buffer = Config.DEFAULT_ENCODING.GetBytes(MakeMessage((int)CommonEnums.SocketType.CheckLogin, msg));
|
|
||||||
length = socket.Send(buffer);
|
|
||||||
if (length > 0)
|
|
||||||
{
|
|
||||||
return Read(objs);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw new Exception("ERROR:消息未送达服务器,与服务器连接可能丢失。");
|
|
||||||
case (int)CommonEnums.SocketType.Logout:
|
|
||||||
break;
|
break;
|
||||||
case (int)CommonEnums.SocketType.HeartBeat:
|
case CommonEnums.SocketType.Logout:
|
||||||
buffer = new byte[2048];
|
break;
|
||||||
buffer = Config.DEFAULT_ENCODING.GetBytes(Convert.ToString(MakeMessage((int)CommonEnums.SocketType.HeartBeat, "心跳检测")));
|
case CommonEnums.SocketType.HeartBeat:
|
||||||
if (socket.Send(buffer) > 0)
|
msg = MakeMessage(type, "心跳检测");
|
||||||
|
if (Send(msg, socket) > 0)
|
||||||
{
|
{
|
||||||
WaitHeartBeat = Task.Run(() =>
|
WaitHeartBeat = Task.Run(() =>
|
||||||
{
|
{
|
||||||
@ -251,8 +249,16 @@ namespace FunGame.Desktop.Utils
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
AddHeartBeatFaileds(main);
|
AddHeartBeatFaileds(main);
|
||||||
break;
|
return false;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
if (Send(msg, socket) > 0)
|
||||||
|
{
|
||||||
|
return Read(objs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new Exception("ERROR:消息未送达服务器,与服务器连接可能丢失。");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -267,6 +273,13 @@ namespace FunGame.Desktop.Utils
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int Send(string msg, Socket socket)
|
||||||
|
{
|
||||||
|
byte[] buffer = Config.DEFAULT_ENCODING.GetBytes(msg);
|
||||||
|
int length = socket.Send(buffer);
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
private void CatchException(Main main, Exception e, bool isDisconnected)
|
private void CatchException(Main main, Exception e, bool isDisconnected)
|
||||||
{
|
{
|
||||||
if (isDisconnected)
|
if (isDisconnected)
|
||||||
@ -307,9 +320,9 @@ namespace FunGame.Desktop.Utils
|
|||||||
return msg[index..];
|
return msg[index..];
|
||||||
}
|
}
|
||||||
|
|
||||||
private string MakeMessage(int type, string msg)
|
private string MakeMessage(CommonEnums.SocketType type, string msg)
|
||||||
{
|
{
|
||||||
return type + ";" + msg;
|
return (int)type + ";" + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Close()
|
private void Close()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user