Exemplo n.º 1
0
func verifyForbidSign(playerId string, _type int, sign string) bool {
	rawstring := fmt.Sprintf("%s-%d-%s-%s", playerId, _type, configBLL.AppId(), configBLL.AppKey())
	if sign == securityUtil.Md5String(rawstring, false) {
		return true
	}

	return false
}
Exemplo n.º 2
0
// 获取新的GUID字符串
// 返回值:
// 新的GUID字符串
func GetNewGUID() string {
	b := make([]byte, 48)
	if _, err := io.ReadFull(rand.Reader, b); err != nil {
		return ""
	}

	return securityUtil.Md5String(base64.URLEncoding.EncodeToString(b), true)
}
Exemplo n.º 3
0
func verifySensitiveSign(message string, sign string) bool {
	rawstring := fmt.Sprintf("%s-%s-%s", message, configBLL.AppId(), configBLL.AppKey())
	if sign == securityUtil.Md5String(rawstring, false) {
		return true
	}

	return false
}
Exemplo n.º 4
0
func TestCheckLoginInfo(t *testing.T) {
	partnerId := 101
	userId := "jordanzuo"
	loginKey := "5e78909a-99bc-4a23-a3ae-752bda01508e"
	loginInfo := securityUtil.Md5String(fmt.Sprintf("UserID=%s&PartnerID=%d&LoginKey=%s", userId, partnerId, loginKey), false)
	if CheckLoginInfo(partnerId, userId, loginInfo) == false {
		t.Errorf("CheckUserInfo失败")
	}
}
Exemplo n.º 5
0
func assembleLoginParam(requestMap map[string]interface{}, currid int) map[string]interface{} {
	id := strconv.Itoa(currid)
	name := fmt.Sprintf("name%d", currid)
	unionId := fmt.Sprintf("%d", rand.New(rand.NewSource(time.Now().UnixNano())).Intn(100))
	extraMsg := "extraMsg"
	sign := securityUtil.Md5String(fmt.Sprintf("%s-%s-%s", id, name, LoginKey), false)

	commandMap := make(map[string]interface{})
	commandMap["Id"] = id
	commandMap["Name"] = name
	commandMap["UnionId"] = unionId
	commandMap["ExtraMsg"] = extraMsg
	commandMap["Sign"] = sign

	requestMap["CommandType"] = 1
	requestMap["Command"] = commandMap

	return requestMap
}
Exemplo n.º 6
0
func main() {
	// 获得输入的信息,并计算sign
	if len(os.Args[1:]) != 4 {
		fmt.Println("输入错误,请重新输入,格式为:id name unionId extraMsg")
		os.Exit(1)
	}

	id, name, unionId, extraMsg := os.Args[1], os.Args[2], os.Args[3], os.Args[4]
	extraMsg = `{"lv":1,"vip":10}`
	sign := securityUtil.Md5String(fmt.Sprintf("%s-%s-%s", id, name, AppKey), false)

	// 创建用于主线程与其它线程通信的channel
	ch := make(chan int)
	clientCh := make(chan *client.Client)
	loginSucceedCh := make(chan int)

	// 启动客户端
	go startClient(ch, clientCh, loginSucceedCh)

	// 通过解析从启动服务器的coroutine中返回的值,来判断启动的结果;0表示启动失败,非0表示启动成功
	if <-ch == 0 {
		fmt.Println("客户端启动失败,请检查")
		os.Exit(1)
	} else {
		fmt.Println("客户端启动成功,可以与服务器进行通信")
	}

	// 客户端对象
	clientObj := <-clientCh

	// 用户登陆
	login(clientObj, id, name, unionId, extraMsg, sign)

	// 发送心跳包
	go heartBeat(ch, clientObj)

	// 与用户交互
	go interaction(ch, clientObj, loginSucceedCh)

	// 收到任何一个goroutine发出来的信息都结束程序
	<-ch
}
Exemplo n.º 7
0
func Login(name, loginKey string, callback func(interface{})) {
	rpc.Request("Player", "Login", []interface{}{configBLL.PartnerId, configBLL.ServerId, configBLL.GameVersionId, resourceVersionBLL.ResourceVersionId, name, securityUtil.Md5String(fmt.Sprintf("%s-%s", name, loginKey), false)}, callback)
}