本文整理汇总了Golang中euphoria/io/heim/proto.Session.SetName方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.SetName方法的具体用法?Golang Session.SetName怎么用?Golang Session.SetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类euphoria/io/heim/proto.Session
的用法示例。
在下文中一共展示了Session.SetName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: join
func (b *Backend) join(ctx scope.Context, rb *RoomBinding, session proto.Session) (string, error) {
client := &proto.Client{}
if !client.FromContext(ctx) {
return "", fmt.Errorf("client data not found in scope")
}
bannedAgentCols, err := allColumns(b.DbMap, BannedAgent{}, "")
if err != nil {
return "", err
}
bannedIPCols, err := allColumns(b.DbMap, BannedIP{}, "")
if err != nil {
return "", err
}
t, err := b.DbMap.Begin()
if err != nil {
return "", err
}
// Check for agent ID bans.
agentBans, err := t.Select(
BannedAgent{},
fmt.Sprintf(
"SELECT %s FROM banned_agent WHERE agent_id = $1 AND (room IS NULL OR room = $2) AND (expires IS NULL OR expires > NOW())",
bannedAgentCols),
session.Identity().ID().String(), rb.RoomName)
if err != nil {
rollback(ctx, t)
return "", err
}
if len(agentBans) > 0 {
logging.Logger(ctx).Printf("access denied to %s: %#v", session.Identity().ID(), agentBans)
if err := t.Rollback(); err != nil {
return "", err
}
return "", proto.ErrAccessDenied
}
// Check for IP bans.
ipBans, err := t.Select(
BannedIP{},
fmt.Sprintf(
"SELECT %s FROM banned_ip WHERE ip = $1 AND (room IS NULL OR room = $2) AND (expires IS NULL OR expires > NOW())",
bannedIPCols),
client.IP, rb.RoomName)
if err != nil {
rollback(ctx, t)
return "", err
}
if len(ipBans) > 0 {
logging.Logger(ctx).Printf("access denied to %s: %#v", client.IP, ipBans)
if err := t.Rollback(); err != nil {
return "", err
}
return "", proto.ErrAccessDenied
}
// Virtualize the session's client address.
var row struct {
Address string `db:"address"`
}
if err := t.SelectOne(&row, "SELECT virtualize_address($1, $2::inet) AS address", rb.RoomName, client.IP); err != nil {
return "", err
}
virtualAddress := row.Address
// Look up session's nick.
nickRow, err := t.Get(Nick{}, string(session.Identity().ID()), rb.RoomName)
if err != nil && err != sql.ErrNoRows {
return "", err
}
if nickRow != nil {
session.SetName(nickRow.(*Nick).Nick)
}
// Write to session log.
// TODO: do proper upsert simulation
entry := &SessionLog{
SessionID: session.ID(),
IP: client.IP,
Room: rb.RoomName,
UserAgent: client.UserAgent,
Connected: client.Connected,
}
if _, err := t.Delete(entry); err != nil {
if rerr := t.Rollback(); rerr != nil {
logging.Logger(ctx).Printf("rollback error: %s", rerr)
}
return "", err
}
if err := t.Insert(entry); err != nil {
if rerr := t.Rollback(); rerr != nil {
logging.Logger(ctx).Printf("rollback error: %s", rerr)
}
return "", err
}
// Broadcast a presence event.
//.........这里部分代码省略.........