mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
introduced ImplicitHosting.
This commit is contained in:
parent
26c0fea840
commit
1677e38935
@ -6,8 +6,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
Password string
|
Password string
|
||||||
AdminPassword string
|
AdminPassword string
|
||||||
|
ImplicitHosting bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Session) Init(cmd *cobra.Command) error {
|
func (Session) Init(cmd *cobra.Command) error {
|
||||||
@ -21,10 +22,16 @@ func (Session) Init(cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.PersistentFlags().Bool("implicit_hosting", true, "allow implicit control switching")
|
||||||
|
if err := viper.BindPFlag("implicit_hosting", cmd.PersistentFlags().Lookup("implicit_hosting")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) Set() {
|
func (s *Session) Set() {
|
||||||
s.Password = viper.GetString("password")
|
s.Password = viper.GetString("password")
|
||||||
s.AdminPassword = viper.GetString("password_admin")
|
s.AdminPassword = viper.GetString("password_admin")
|
||||||
|
s.ImplicitHosting = viper.GetBool("implicit_hosting")
|
||||||
}
|
}
|
||||||
|
@ -241,3 +241,7 @@ func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Ses
|
|||||||
listener(payload[0].(*SessionCtx))
|
listener(payload[0].(*SessionCtx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (manager *SessionManagerCtx) ImplicitHosting() bool {
|
||||||
|
return manager.config.ImplicitHosting
|
||||||
|
}
|
||||||
|
@ -15,6 +15,7 @@ type SystemInit struct {
|
|||||||
ControlHost ControlHost `json:"control_host"`
|
ControlHost ControlHost `json:"control_host"`
|
||||||
ScreenSize ScreenSize `json:"screen_size"`
|
ScreenSize ScreenSize `json:"screen_size"`
|
||||||
Members map[string]MemberData `json:"members"`
|
Members map[string]MemberData `json:"members"`
|
||||||
|
ImplicitHosting bool `json:"implicit_hosting"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SystemAdmin struct {
|
type SystemAdmin struct {
|
||||||
|
@ -48,6 +48,7 @@ type SessionManager interface {
|
|||||||
OnHostCleared(listener func(session Session))
|
OnHostCleared(listener func(session Session))
|
||||||
OnConnected(listener func(session Session))
|
OnConnected(listener func(session Session))
|
||||||
OnDisconnected(listener func(session Session))
|
OnDisconnected(listener func(session Session))
|
||||||
|
ImplicitHosting() bool
|
||||||
|
|
||||||
// auth
|
// auth
|
||||||
Authenticate(r *http.Request) (Session, error)
|
Authenticate(r *http.Request) (Session, error)
|
||||||
|
@ -30,16 +30,16 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Allow implicit requests.
|
if !h.sessions.ImplicitHosting() {
|
||||||
host := h.sessions.GetHost()
|
// tell session if there is a host
|
||||||
if host != nil {
|
if host := h.sessions.GetHost(); host != nil {
|
||||||
// tell session there is a host
|
return session.Send(
|
||||||
return session.Send(
|
message.ControlHost{
|
||||||
message.ControlHost{
|
Event: event.CONTROL_HOST,
|
||||||
Event: event.CONTROL_HOST,
|
HasHost: true,
|
||||||
HasHost: true,
|
HostID: host.ID(),
|
||||||
HostID: host.ID(),
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h.sessions.SetHost(session)
|
h.sessions.SetHost(session)
|
||||||
|
@ -34,15 +34,16 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
|||||||
|
|
||||||
return session.Send(
|
return session.Send(
|
||||||
message.SystemInit{
|
message.SystemInit{
|
||||||
Event: event.SYSTEM_INIT,
|
Event: event.SYSTEM_INIT,
|
||||||
MemberId: session.ID(),
|
MemberId: session.ID(),
|
||||||
ControlHost: controlHost,
|
ControlHost: controlHost,
|
||||||
Members: members,
|
ScreenSize: message.ScreenSize{
|
||||||
ScreenSize: message.ScreenSize{
|
|
||||||
Width: size.Width,
|
Width: size.Width,
|
||||||
Height: size.Height,
|
Height: size.Height,
|
||||||
Rate: int(size.Rate),
|
Rate: int(size.Rate),
|
||||||
},
|
},
|
||||||
|
Members: members,
|
||||||
|
ImplicitHosting: h.sessions.ImplicitHosting(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user