同步代码
This commit is contained in:
50
core/user.go
Normal file
50
core/user.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/aceld/zinx/ziface"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// User User 对象
|
||||
type User struct {
|
||||
UID string //ID
|
||||
Conn ziface.IConnection //当前User的连接
|
||||
LoginState bool
|
||||
LoginCount int
|
||||
AlarmType string
|
||||
UserName string
|
||||
SeqNo string // 登录随机码
|
||||
RemoteIp string
|
||||
}
|
||||
|
||||
// NewUser 创建一个user对象
|
||||
func NewUser(conn ziface.IConnection, addr string) *User {
|
||||
p := &User{
|
||||
UID: uuid.NewString(),
|
||||
Conn: conn,
|
||||
RemoteIp: addr,
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// LostConnection User下线
|
||||
func (p *User) LostConnection(m *ChannelManager) {
|
||||
m.RemoveUserByPID(p.UID)
|
||||
}
|
||||
|
||||
// SendMsg /*
|
||||
func (p *User) SendMsg(msgID uint32, msg []byte) {
|
||||
if p.Conn == nil {
|
||||
fmt.Println("connection in player is nil")
|
||||
return
|
||||
}
|
||||
|
||||
//调用SendMsg发包
|
||||
if err := p.Conn.SendMsg(msgID, msg); err != nil {
|
||||
fmt.Println("Player SendMsg error !")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user