Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

Commit

Permalink
add role rename protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
fztcjjl committed Nov 28, 2015
1 parent 3da1a78 commit cfa5fd8
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
27 changes: 27 additions & 0 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,33 @@ function CMD.roleinit(token, sdkid, name)
end
end

function CMD.rolerename(token, sdkid, name)
CMD.login(token, sdkid, true)

local data = { name = name }
send_request(encode("user.RoleRenameRequest", data))
local ok, msg, sess = recv_response(read_package())
msg = decode(msg)
if msg.errmsg.code == 0 then
print("role rename succ")
else
print(string.format("error with code=%d", msg.errmsg.code))
end
end

function CMD.userinfo(token, sdkid)
CMD.login(token, sdkid, true)

send_request(encode("user.UserInfoRequest", {}))
local ok, msg, sess = recv_response(read_package())
msg = decode(msg)
if msg.errmsg.code == 0 then
print("userinfo succ")
else
print(string.format("error with code=%d", msg.errmsg.code))
end
end

local function start(cmd, ...)
if not cmd or cmd == "" then
cmd = "help"
Expand Down
2 changes: 1 addition & 1 deletion common/dbmgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ function CMD.update(tbname, row, type, nosync)
skynet.call("dbsync", "lua", "sync", sql)
end

return result
return true
end

function CMD.get_table_key(tbname, type)
Expand Down
15 changes: 15 additions & 0 deletions game/user/role.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ function response.roleinit(uid, name)
end
return errno
end

function response.rolerename(uid, name)
local errno = E_SUCCESS
if not user_dc.req.check_role_exists(uid) then
LOG_ERROR("uid %d has not a role, role rename failed", uid)
return ErrorCode.E_ROLE_NOT_EXISTS
end

local ret = user_dc.req.setvalue(uid, "name", name)

if not ret then
return ErrorCode.E_DB_ERROR
end
return errno
end
7 changes: 7 additions & 0 deletions game/user/user.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ function response.RoleInitRequest(data)
return name, resp, errno
end

function response.RoleRenameRequest(data)
local args = pb_decode(data)
local errno = role_obj.req.rolerename(args.uid, args.name)
local name, resp = pb_encode("user.RoleRenameResponse", {})
return name, resp, errno
end

function response.UserInfoRequest(data)
local args = pb_decode(data)
local userinfo = user_dc.req.get(args.uid)
Expand Down
3 changes: 2 additions & 1 deletion global/errno.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ ErrorCode = {
E_SUCCESS = 0, -- 成功
E_ROLE_EXISTS = 1, -- 玩家角色已存在
E_DB_ERROR = 2, -- 数据库操作失败
}
E_ROLE_NOT_EXISTS = 3, -- 玩家角色不存在
}
7 changes: 5 additions & 2 deletions protocol/user.pb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

�
�

user.protouser"
RoleInitRequest
name ( "
RoleInitResonpse"
RoleInitResonpse"!
RoleRenameRequest
name ( "
RoleRenameResponse"
UserInfoRequest"g
UserInfoResponse
uid (
Expand Down
9 changes: 9 additions & 0 deletions protocol/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ message RoleInitResonpse {

}

// 角色改名
message RoleRenameRequest {
required string name = 1;
}

message RoleRenameResponse {

}

message UserInfoRequest {

}
Expand Down

0 comments on commit cfa5fd8

Please sign in to comment.