示例#1
0
func (mc *msgCreator) PlayerEnter(idx int, info *com.UserInfo) string {
	ntf := &PlayerEnterNtf{
		Info:  *info,
		Index: idx,
	}
	return com.MakeMsgString(com.Cmd_Cow_PlayerEnterNtf, 0, ntf)
}
示例#2
0
func TestServer2(t *testing.T) {
	go func() {
		once.Do(startServer2)
	}()

	//	time.Sleep(5 * time.Second)

	conn, err := newClient()
	defer conn.Close()

	if err != nil {
		log.Error("newClient: ", err.Error())
		return
	}

	var msg string

	//	log.Info("test:register")
	//	msg = []byte(`{"cmd":100,
	//		"content":"{\"account\":\"testUtf\",\"psw\":\"pswlk22\"}"
	//		}`)
	//	sendMsg(conn, msg)
	//	time.Sleep(1 * time.Second)

	log.Info("test:cmdLoginReq1")
	//	msg = []byte(`{"cmd":104,"content":"{\"account\":\"testUtf\",\"psw\":\"pswlk22\"}"}`)
	msg = com.MakeMsgString(com.Cmd_Ag_LoginReq, 0, &LoginReq{"testUtf", "pswlk22"})
	sendMsg(conn, msg)
	time.Sleep(1 * time.Second)

	//	log.Info("test:cmdLoginReq2")
	//	msg = []byte(`{"cmd":104,"content":"{\"account\":\"testUtf\",\"psw\":\"p\"}"}`)
	//	sendMsg(conn, msg)
	//	time.Sleep(1 * time.Second)

	log.Info("test:handleInfo")
	//	msg = []byte(`{"cmd":106}`)
	//	msg = []byte(`{"cmd":106,"content":"{\"account\":\"testUtf\",\"psw\":\"p\"}"}`)
	msg = com.MakeMsgString(com.Cmd_Ag_InfoReq, 0, nil)
	sendMsg(conn, msg)
	time.Sleep(11 * time.Second)

	log.Info("test:enter game room")
	msg = com.MakeMsgString(com.Cmd_Ag_ToGameReq, 0, nil)

}
示例#3
0
func (m *model) handleInfo(content string) (resp string, err error) {
	args := &dao.Args{Id: m.id}
	log.Debugf("handleInfo args=%+v", args)
	var reply dao.User_InfoReply
	if err = m.dao.Call("User.GetInfo", args, &reply); err != nil {
		return
	}
	log.Debugf("handleInfo, reply=%+v", reply)
	resp = com.MakeMsgString(com.Cmd_Ag_InfoResp, reply.Code, reply.Info)
	return
}
示例#4
0
文件: game.go 项目: lkj01010/chesssrv
func (g *Game) handlePlayerEnterOrLeave(el PlayerEnterOrLeave) {
	if el.isEnter {
		player := NewPlayer(el.id, el.info, el.rcvr, el.sendFunc)
		g.players = append(g.players, player)

		// notify game "i come"
		el.rcvr <- com.MakeMsgString(com.Cmd_Game_EnterReq, 0, nil)

	} else {
		// todo:
	}
}
示例#5
0
func (m *model) handleAuth(content string) (resp string, err error) {
	var req AuthReq
	if err = json.Unmarshal([]byte(content), &req); err != nil {
		return
	}
	args := &dao.User_AuthArgs{req.Account, req.Psw}
	var reply dao.User_AuthReply
	if err = m.dao.Call("User.Auth", args, &reply); err != nil {
		return
	}
	resp = com.MakeMsgString(com.Cmd_Ag_AuthResp, reply.Code, nil)
	return
}
示例#6
0
func (m *model) handleRegister(content string) (resp string, err error) {
	//	daocli.
	var req RegisterReq
	if err = json.Unmarshal([]byte(content), &req); err != nil {
		log.Error("content=", content, ", err: ", err.Error())
		return
	}
	args := &dao.User_RegisterArgs{req.Account, req.Psw}
	var reply dao.Reply
	log.Debugf("req : %#v", req)
	//	if err = h.dc.UserRegister(&args, &reply); err != nil {
	if err = m.dao.Call("User.Register", args, &reply); err != nil {
		return
	}
	log.Infof("User.Register %+v -> %+v", args, reply)
	resp = com.MakeMsgString(com.Cmd_Ag_RegisterResp, reply.Code, nil)
	return
}
示例#7
0
func (m *model) handleLogin(content string) (resp string, err error) {
	var req LoginReq
	if err = json.Unmarshal([]byte(content), &req); err != nil {
		return
	}
	args := &dao.User_AuthArgs{req.Account, req.Psw}
	var reply dao.User_AuthReply
	if err = m.dao.Call("User.Auth", args, &reply); err != nil {
		return
	}
	if reply.Code == com.E_Success {
		//登录成功,记录用户id
		m.id = reply.Id
		m.isLogin = true
	}
	resp = com.MakeMsgString(com.Cmd_Ag_LoginResp, reply.Code, nil)
	return
}
示例#8
0
func (p *playerAgent) handleEnterReq(contentstr string) (err error) {
	_, ok := modelInst.playerGames[p.connId]
	if ok {
		// 已经在游戏中,报错
		err = com.ErrAlreadyInGame
		log.Warning("game:model:handle:player enter req, err=", err.Error())
		return
	} else {
		var content EnterGameReq
		if err = json.Unmarshal([]byte(contentstr), &content); err != nil {
			return
		}
		p.id = content.Id

		//判断钱是否够
		isCoinEnough := (p.info.Coin >= RoomEnterCoin[content.RoomType])

		// 够入场费
		if isCoinEnough {
			// 塞进房间
			rt := RoomType(content.RoomType)
			if rt.IsValid() {
				game := modelInst.GetFreeGameByType(rt)
				game.PlayerEnter(content.Id, p.info, p.toGame, p.Send)
			} else {
				log.Warningf("game:model:handle:roomtype invalid, rt=%+v", content.RoomType)
				err = com.ErrRoomTypeInvalid
				return
			}
		} else {
			// 不够入场费
			// 返回response
			resp := com.MakeMsgString(com.Cmd_Game_EnterResp, com.E_CoinNotEnough, nil)
			p.Send(resp)
			return
		}
	}
	return
}
示例#9
0
func (mc *msgCreator) Settle(settleNtf *SettleNtf) string {
	return com.MakeMsgString(com.Cmd_Cow_SettleNtf, 0, settleNtf)
}
示例#10
0
func (mc *msgCreator) hasNoEnoughMoney() string {
	return com.MakeMsgString(com.Cmd_Cow_NotEnoughMoneyNtf, 0, nil)
}