码迷,mamicode.com
首页 > 编程语言 > 详细

Netty实现Unity登录验证(一)

时间:2017-03-04 00:31:37      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:block   mysq   engine   close   模型设计   场景   comm   cte   引导   

开发环境:JDK1.7,Uniyt5.4.2,数据格式ProtoStuff1.08,Netty5.0.0,数据库MySQL。
代码对应关系如下:

技术分享

首先实现数据模型设计,用于ProtoStuff数据传输。 这里的类服务端与客户端对应,以便消息的序列化与反序列化。

技术分享
 1 package com.netty.model;
 2 
 3 import java.util.List;
 4 
 5 public class SocketModel {
 6 
 7     private int type;  //消息类型
 8     private int area;  //消息区域
 9     private int command;  //消息指令
10     private List<String> message;  //消息内容
11 
12     public void setType(int type)
13     {
14         this.type = type;
15     }
16 
17     public int getType()
18     {
19         return type;
20     }
21 
22     public void setArea(int area)
23     {
24         this.area = area;
25     }
26 
27     public int getArea()
28     {
29         return area;
30     }
31 
32     public void setCommand(int command)
33     {
34         this.command = command;
35     }
36 
37     public int getCommand()
38     {
39         return command;
40     }
41 
42     public void setMessage(List<String> message)
43     {
44         this.message = message;
45     }
46 
47     public List<String> getMessage()
48     {
49         return message;
50     }
51 }
SocketModel(服务端通讯消息模型)
技术分享
 1 using System.Collections.Generic;
 2 using ProtoBuf;
 3 
 4 [ProtoContract]
 5 public class SocketModel {
 6 
 7     [ProtoMember(1)]
 8     private int type;  //消息类型
 9 
10     [ProtoMember(2)]
11     private int area;  //消息区域
12 
13     [ProtoMember(3)]
14     private int command;  //消息指令
15 
16     [ProtoMember(4)]
17     private List<string> message;  //消息内容
18 
19     public SocketModel()
20     {
21 
22     }
23 
24     public SocketModel(int type, int area, int command, List<string> message)
25     {
26         this.type = type;
27         this.area = area;
28         this.command = command;
29         this.message = message;
30     }
31 
32     public void SetType(int type)
33     {
34         this.type = type;
35     }
36 
37     public int GetType()
38     {
39         return type;
40     }
41 
42     public void SetArea(int area)
43     {
44         this.area = area;
45     }
46 
47     public int GetArea()
48     {
49         return area;
50     }
51 
52     public void SetCommand(int command)
53     {
54         this.command = command;
55     }
56 
57     public int GetCommand()
58     {
59         return command;
60     }
61 
62     public void SetMessage(List<string> message)
63     {
64         this.message = message;
65     }
66 
67     public List<string> GetMessage()
68     {
69         return message;
70     }
71 }
SocketModel(客户端通讯消息模型)
技术分享
 1 package com.netty.protocol;
 2 
 3 public class LoginProtocol {
 4     
 5     public static final int Area_LoginRequest = 5;
 6     public static final int Area_LoginResponse = 6;
 7     
 8     public static final int Login_InvalidMessage = 0;
 9     public static final int Login_InvalidUsername = 1;
10     public static final int Login_InvalidPassword = 2;
11     public static final int Login_Succeed = 10;
12     
13 }
LoginProtocol(服务端登陆消息模型)
技术分享
1 package com.netty.protocol;
2 
3 public class TypeProtocol {
4     public static final int TYPE_LOGIN = 0;   //登录
5     public static final int TYPE_USER = 1;    //注册用户
6     public static final int TYPE_WIZARD = 2;  //用户引导
7     public static final int TYPE_BATTLE = 3;  //战斗
8 }
TypeProtocol(服务端场景类型ID)
技术分享
 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class LoginProtocol{
 5 
 6     public const int Area_LoginRequest = 5;    //login request
 7     public const int Area_LoginResponse = 6;    //login response
 8 
 9     public const int Login_InvalidMessage = 0;   //invalid message
10     public const int Login_InvalidUsername = 1;   //invalid login username
11     public const int Login_InvalidPassword = 2;   //invalid login password
12 
13     public const int Login_Succeed = 10;    //Login success
14 }
LoginProtocol(客户端登录消息类型)
技术分享
 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class TypeProtocol {
 5 
 6     public const int TYPE_LOGIN = 0;
 7     public const int TYPE_USER = 1;
 8     public const int TYPE_WIZARD = 2;
 9     public const int TYPE_BATTLE = 3;
10 }
TypeProtocol(客户端场景类型ID)

引用包下载地址(Netty&ProtoStuff&MySQL)

 

Netty实现Unity登录验证(一)

标签:block   mysq   engine   close   模型设计   场景   comm   cte   引导   

原文地址:http://www.cnblogs.com/DragonXin/p/6498110.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!