commonly commit
This commit is contained in:
@@ -20,5 +20,6 @@ namespace Interact
|
||||
public const string NickName = "NickName";
|
||||
public const string Motto = "Motto";
|
||||
public const string UGroup = "UGroup";
|
||||
public const string Photo = "Photo";
|
||||
}
|
||||
}
|
||||
|
||||
+19
-9
@@ -4,6 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
//StormClient对数据的处理相关内容
|
||||
|
||||
@@ -33,7 +35,7 @@ namespace Interact
|
||||
switch (jsonObj[AttrNames.Operation].ToString())
|
||||
{
|
||||
case Operations.Login:
|
||||
HandleLoginResult(GetResultHead(jsonObj), data);
|
||||
HandleLoginResult(jsonObj, data);
|
||||
break;
|
||||
case Operations.Panic:
|
||||
HandlePanic(GetResultHead(jsonObj));
|
||||
@@ -68,23 +70,31 @@ namespace Interact
|
||||
}
|
||||
|
||||
//处理登录反馈消息
|
||||
private static void HandleLoginResult(ResultHead head, byte[] data)
|
||||
private static void HandleLoginResult(JObject head, byte[] data)
|
||||
{
|
||||
//提取结果包头
|
||||
ResultHead resultHead = GetResultHead(head);
|
||||
//发起登录完成事件
|
||||
if (head.Error != "")
|
||||
if (head[AttrNames.Error].ToString() != "")
|
||||
{
|
||||
OnLoginDone?.Invoke(head, null);
|
||||
OnLoginDone?.Invoke(resultHead, null);
|
||||
return;
|
||||
}
|
||||
JObject dataObj = (JObject)JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data));
|
||||
User user = new User
|
||||
{
|
||||
Name = dataObj[AttrNames.User].ToString(),
|
||||
NickName = dataObj[AttrNames.NickName].ToString(),
|
||||
Motto = dataObj[AttrNames.Motto].ToString(),
|
||||
Group = (UserGroup)Enum.Parse(typeof(UserGroup), dataObj[AttrNames.UGroup].ToString())
|
||||
Name = head[AttrNames.User].ToString(),
|
||||
NickName = head[AttrNames.NickName].ToString(),
|
||||
Motto = head[AttrNames.Motto].ToString(),
|
||||
Group = (UserGroup)Enum.Parse(typeof(UserGroup), dataObj[AttrNames.UGroup].ToString()),
|
||||
Photo = User.DefaultPhoto
|
||||
};
|
||||
OnLoginDone?.Invoke(head, user);
|
||||
if (int.Parse(head[AttrNames.Photo].ToString()) > 0)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(data);
|
||||
user.Photo = Image.FromStream(ms);
|
||||
} //用户头像数据
|
||||
OnLoginDone?.Invoke(resultHead, user);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
+12
-2
@@ -9,13 +9,23 @@ namespace Interact
|
||||
//定义一则用户接收到的消息
|
||||
public class Message
|
||||
{
|
||||
public Message() { }
|
||||
public Message(string text, User Receiver)
|
||||
{
|
||||
When = DateTime.Now;
|
||||
From = User.Me;
|
||||
To = Receiver;
|
||||
Text = text;
|
||||
}
|
||||
|
||||
/*保留
|
||||
public const UInt32 MaxHeadLength = 4096; //最大包头长度
|
||||
public const UInt32 MaxMessageLength = 0x6400000; //最大数据长度
|
||||
*/
|
||||
public DateTime When { get; } //服务器接收时间
|
||||
public User From; //发送者
|
||||
public string Content; //消息内容
|
||||
public User From; //消息发送者
|
||||
public User To; //消息接收者
|
||||
public string Text; //消息内容
|
||||
|
||||
//将消息保存到数据库(保留)
|
||||
protected bool Save() { return false; }
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Interact
|
||||
public class User
|
||||
{
|
||||
public static User Me; //当前用户
|
||||
public static Image DefaultPhoto; //默认头像
|
||||
|
||||
public string Name; //用户名
|
||||
public string NickName; //昵称
|
||||
|
||||
Reference in New Issue
Block a user