You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
2.7 KiB
137 lines
2.7 KiB
3 years ago
|
package ws
|
||
3 years ago
|
|
||
|
import "git.reya.zone/reya/hexmap/server/action"
|
||
|
|
||
|
func (x *ServerCommandPB) ToGo() (ServerCommand, error) {
|
||
|
switch msg := x.Command.(type) {
|
||
|
case *ServerCommandPB_Hello:
|
||
|
return msg.Hello.ToGo()
|
||
|
case *ServerCommandPB_Refresh:
|
||
|
return msg.Refresh.ToGo()
|
||
|
case *ServerCommandPB_Ok:
|
||
|
return msg.Ok.ToGo(), nil
|
||
|
case *ServerCommandPB_Failed:
|
||
|
return msg.Failed.ToGo(), nil
|
||
|
case *ServerCommandPB_Act:
|
||
|
return msg.Act.ToGo()
|
||
|
default:
|
||
|
panic("A case was missed in ServerCommandPB.ToGo!")
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func (x *ServerHelloPB) ToGo() (*ServerHello, error) {
|
||
3 years ago
|
state, err := x.State.ToGo()
|
||
|
if err != nil {
|
||
3 years ago
|
return nil, err
|
||
3 years ago
|
}
|
||
3 years ago
|
return &ServerHello{
|
||
3 years ago
|
Version: x.Version,
|
||
|
State: &state,
|
||
|
}, nil
|
||
|
}
|
||
|
|
||
3 years ago
|
func (s *ServerHello) ToServerPB() *ServerCommandPB {
|
||
3 years ago
|
return &ServerCommandPB{
|
||
|
Command: &ServerCommandPB_Hello{
|
||
|
Hello: &ServerHelloPB{
|
||
|
Version: s.Version,
|
||
|
State: s.State.ToPB(),
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func (x *ServerRefreshPB) ToGo() (*ServerRefresh, error) {
|
||
3 years ago
|
state, err := x.State.ToGo()
|
||
|
if err != nil {
|
||
3 years ago
|
return nil, err
|
||
3 years ago
|
}
|
||
3 years ago
|
return &ServerRefresh{
|
||
3 years ago
|
State: &state,
|
||
|
}, nil
|
||
|
}
|
||
|
|
||
3 years ago
|
func (s *ServerRefresh) ToServerPB() *ServerCommandPB {
|
||
3 years ago
|
return &ServerCommandPB{
|
||
|
Command: &ServerCommandPB_Refresh{
|
||
|
Refresh: &ServerRefreshPB{
|
||
|
State: s.State.ToPB(),
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func (x *ServerOKPB) ToGo() *ServerOK {
|
||
3 years ago
|
ids := make(IDSlice, len(x.Ids))
|
||
|
copy(ids, x.Ids)
|
||
3 years ago
|
return &ServerOK{
|
||
3 years ago
|
IDs: ids,
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func (s *ServerOK) ToServerPB() *ServerCommandPB {
|
||
3 years ago
|
ids := make([]uint32, len(s.IDs))
|
||
|
copy(ids, s.IDs)
|
||
|
return &ServerCommandPB{
|
||
|
Command: &ServerCommandPB_Ok{
|
||
|
Ok: &ServerOKPB{
|
||
|
Ids: ids,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func (x *ServerFailedPB) ToGo() *ServerFailed {
|
||
3 years ago
|
ids := make(IDSlice, len(x.Ids))
|
||
|
copy(ids, x.Ids)
|
||
3 years ago
|
return &ServerFailed{
|
||
3 years ago
|
IDs: ids,
|
||
|
Error: x.Error,
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func (s *ServerFailed) ToServerPB() *ServerCommandPB {
|
||
3 years ago
|
ids := make([]uint32, len(s.IDs))
|
||
|
copy(ids, s.IDs)
|
||
|
return &ServerCommandPB{
|
||
|
Command: &ServerCommandPB_Failed{
|
||
|
Failed: &ServerFailedPB{
|
||
|
Ids: ids,
|
||
|
Error: s.Error,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func (x *ServerActPB) ToGo() (*ServerAct, error) {
|
||
3 years ago
|
actions := make(action.ServerSlice, len(x.Actions))
|
||
|
for index, act := range x.Actions {
|
||
|
convertedAct, err := act.ToGo()
|
||
|
if err != nil {
|
||
3 years ago
|
return nil, err
|
||
3 years ago
|
}
|
||
|
actions[index] = convertedAct
|
||
|
}
|
||
3 years ago
|
return &ServerAct{
|
||
3 years ago
|
Actions: actions,
|
||
|
}, nil
|
||
|
}
|
||
|
|
||
3 years ago
|
func (s *ServerAct) ToServerPB() *ServerCommandPB {
|
||
3 years ago
|
actions := make([]*action.ServerActionPB, len(s.Actions))
|
||
|
for index, act := range s.Actions {
|
||
|
actions[index] = act.ToServerPB()
|
||
|
}
|
||
|
return &ServerCommandPB{
|
||
|
Command: &ServerCommandPB_Act{
|
||
|
Act: &ServerActPB{
|
||
|
Actions: actions,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func (*SocketClosed) ToServerPB() *ServerCommandPB {
|
||
3 years ago
|
return nil
|
||
|
}
|