本文整理汇总了Golang中github.com/TF2Stadium/Helen/helpers.NewTPError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTPError函数的具体用法?Golang NewTPError怎么用?Golang NewTPError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTPError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ServerVerify
func (Lobby) ServerVerify(so *wsevent.Client, args struct {
Server *string `json:"server"`
Rconpwd *string `json:"rconpwd"`
}) interface{} {
if !validAddress.MatchString(*args.Server) {
return helpers.NewTPError("Invalid Server Address", -1)
}
var count int
db.DB.Table("server_records").Where("host = ?", *args.Server).Count(&count)
if count != 0 {
return helpers.NewTPError("A lobby is already using this server.", -1)
}
info := &models.ServerRecord{
Host: *args.Server,
RconPassword: *args.Rconpwd,
}
db.DB.Save(info)
defer db.DB.Where("host = ?", info.Host).Delete(models.ServerRecord{})
err := models.VerifyInfo(*info)
if err != nil {
return helpers.NewTPErrorFromError(err)
}
return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:29,代码来源:lobby.go
示例2: TrySettingUp
func (lobby *Lobby) TrySettingUp() *helpers.TPError {
if _, ok := LobbyServerSettingUp[lobby.ID]; ok {
return helpers.NewTPError("Lobby setup already in progress", -1)
}
if lobby.Server == nil {
return helpers.NewTPError("Lobby doesn't have a server attached", -1)
}
LobbyServerSettingUp[lobby.ID] = time.Now()
err := lobby.Server.Setup()
delete(LobbyServerSettingUp, lobby.ID)
if err != nil {
lobby.Close()
return helpers.NewTPError(err.Error(), -1)
}
lobby.State = LobbyStateWaiting
db.DB.Save(lobby)
return nil
}
开发者ID:UnnoTed,项目名称:Helen,代码行数:25,代码来源:lobby.go
示例3: removePlayerFromLobby
func removePlayerFromLobby(lobbyId uint, steamId string) (*models.Lobby, *models.Player, *helpers.TPError) {
player, tperr := models.GetPlayerBySteamId(steamId)
if tperr != nil {
return nil, nil, tperr
}
lob, tperr := models.GetLobbyById(lobbyId)
if tperr != nil {
return nil, nil, tperr
}
switch lob.State {
case models.LobbyStateInProgress:
return lob, player, helpers.NewTPError("Lobby is in progress.", 1)
case models.LobbyStateEnded:
return lob, player, helpers.NewTPError("Lobby has closed.", 1)
}
_, err := lob.GetPlayerSlot(player)
if err != nil {
return lob, player, helpers.NewTPError("Player not playing", 2)
}
if err := lob.RemovePlayer(player); err != nil {
return lob, player, err
}
return lob, player, lob.AddSpectator(player)
}
开发者ID:demipixel,项目名称:Helen,代码行数:29,代码来源:lobby.go
示例4: LobbyClose
func (Lobby) LobbyClose(so *wsevent.Client, args struct {
Id *uint `json:"id"`
}) interface{} {
player := chelpers.GetPlayerFromSocket(so.ID)
lob, tperr := models.GetLobbyByIDServer(uint(*args.Id))
if tperr != nil {
return tperr
}
if player.SteamID != lob.CreatedBySteamID && player.Role != helpers.RoleAdmin {
return helpers.NewTPError("Player not authorized to close lobby.", -1)
}
if lob.State == models.LobbyStateEnded {
return helpers.NewTPError("Lobby already closed.", -1)
}
lob.Close(true)
notify := fmt.Sprintf("Lobby closed by %s", player.Name)
models.SendNotification(notify, int(lob.ID))
return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:26,代码来源:lobby.go
示例5: LobbyServerReset
func (Lobby) LobbyServerReset(so *wsevent.Client, args struct {
ID *uint `json:"id"`
}) interface{} {
player := chelpers.GetPlayerFromSocket(so.ID)
lobby, tperr := models.GetLobbyByID(*args.ID)
if player.SteamID != lobby.CreatedBySteamID || player.Role != helpers.RoleAdmin {
return helpers.NewTPError("Player not authorized to reset server.", -1)
}
if tperr != nil {
return tperr
}
if lobby.State == models.LobbyStateEnded {
return helpers.NewTPError("Lobby has ended", 1)
}
if err := models.ReExecConfig(lobby.ID); err != nil {
return helpers.NewTPErrorFromError(err)
}
return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:26,代码来源:lobby.go
示例6: ChatDelete
func (Chat) ChatDelete(so *wsevent.Client, args struct {
ID *int `json:"id"`
Room *uint `json:"room"`
}) interface{} {
if err := chelpers.CheckPrivilege(so, helpers.ActionDeleteChat); err != nil {
return err
}
message := &models.ChatMessage{}
err := db.DB.Table("chat_messages").Where("room = ? AND id = ?", args.Room, args.ID).First(message).Error
if message.Bot {
return helpers.NewTPError("Cannot delete notification messages", -1)
}
if err != nil {
return helpers.NewTPError("Can't find message", -1)
}
player, _ := models.GetPlayerByID(message.PlayerID)
message.Deleted = true
message.Timestamp = message.CreatedAt.Unix()
message.Save()
message.Message = "<deleted>"
message.Player = models.DecoratePlayerSummary(player)
message.Player.Tags = append(message.Player.Tags, "deleted")
message.Send()
return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:29,代码来源:chat.go
示例7: ChatSend
func (Chat) ChatSend(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, 0, true)
if reqerr != nil {
return reqerr.Encode()
}
var args struct {
Message *string `json:"message"`
Room *int `json:"room"`
}
err := chelpers.GetParams(data, &args)
if err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
player, tperr := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
if tperr != nil {
return tperr.Encode()
}
//helpers.Logger.Debug("received chat message: %s %s", *args.Message, player.Name)
if *args.Room > 0 {
spec := player.IsSpectatingId(uint(*args.Room))
//Check if player has either joined, or is spectating lobby
lobbyId, tperr := player.GetLobbyId()
if tperr != nil && !spec && lobbyId != uint(*args.Room) {
return helpers.NewTPError("Player is not in the lobby.", 5).Encode()
}
} else {
// else room is the lobby list room
*args.Room, _ = strconv.Atoi(config.Constants.GlobalChatRoom)
}
if (*args.Message)[0] == '\n' {
return helpers.NewTPError("Cannot send messages prefixed with newline", 4).Encode()
}
if len(*args.Message) > 120 {
return helpers.NewTPError("Message too long", 4).Encode()
}
message := models.NewChatMessage(*args.Message, *args.Room, player)
db.DB.Save(message)
bytes, _ := json.Marshal(message)
broadcaster.SendMessageToRoom(fmt.Sprintf("%s_public",
chelpers.GetLobbyRoom(uint(*args.Room))),
"chatReceive", string(bytes))
if strings.HasPrefix(*args.Message, "!admin") {
chelpers.SendToSlack(*args.Message, player.Name, player.SteamId)
}
return chelpers.EmptySuccessJS
}
开发者ID:demipixel,项目名称:Helen,代码行数:56,代码来源:chat.go
示例8: ChatSend
func (Chat) ChatSend(so *wsevent.Client, args struct {
Message *string `json:"message"`
Room *int `json:"room"`
}) interface{} {
playerID := chelpers.GetPlayerID(so.ID)
now := time.Now().Unix()
if now-lastChatTime[playerID] == 0 {
return helpers.NewTPError("You're sending messages too quickly", -1)
}
lastChatTime[playerID] = now
player, _ := models.GetPlayerByID(playerID)
//logrus.Debug("received chat message: %s %s", *args.Message, player.Name)
if *args.Room > 0 {
var count int
spec := player.IsSpectatingID(uint(*args.Room))
//Check if player has either joined, or is spectating lobby
db.DB.Table("lobby_slots").Where("lobby_id = ? AND player_id = ?", *args.Room, player.ID).Count(&count)
if !spec && count == 0 {
return helpers.NewTPError("Player is not in the lobby.", 5)
}
} else {
// else room is the lobby list room
*args.Room, _ = strconv.Atoi(config.GlobalChatRoom)
}
switch {
case len(*args.Message) == 0:
return helpers.NewTPError("Cannot send an empty message", 4)
case (*args.Message)[0] == '\n':
return helpers.NewTPError("Cannot send messages prefixed with newline", 4)
case len(*args.Message) > 150:
return helpers.NewTPError("Message too long", 4)
}
message := models.NewChatMessage(*args.Message, *args.Room, player)
message.Save()
if strings.HasPrefix(*args.Message, "!admin") {
chelpers.SendToSlack(*args.Message, player.Name, player.SteamID)
return chelpers.EmptySuccessJS
}
message.Send()
return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:52,代码来源:chat.go
示例9: LobbyGetPlayerSlot
func LobbyGetPlayerSlot(lobbytype LobbyType, teamStr string, classStr string) (int, *helpers.TPError) {
team, ok := teamMap[teamStr]
if !ok {
return -1, helpers.NewTPError("Invalid team", -1)
}
class, ok := TypeClassMap[lobbytype][classStr]
if !ok {
return -1, helpers.NewTPError("Invalid class", -1)
}
return team*NumberOfClassesMap[lobbytype] + class, nil
}
开发者ID:demipixel,项目名称:Helen,代码行数:13,代码来源:classMaps.go
示例10: LobbyBan
func (Lobby) LobbyBan(so *wsevent.Client, args struct {
Id *uint `json:"id"`
Steamid *string `json:"steamid"`
}) interface{} {
steamId := *args.Steamid
selfSteamId := chelpers.GetSteamId(so.ID)
if steamId == selfSteamId {
return helpers.NewTPError("Player can't kick himself.", -1)
}
if ok, tperr := playerCanKick(*args.Id, selfSteamId); !ok {
return tperr
}
lob, player, tperr := removePlayerFromLobby(*args.Id, steamId)
if tperr != nil {
return tperr
}
lob.BanPlayer(player)
hooks.AfterLobbyLeave(lob, player)
// broadcaster.SendMessage(steamId, "sendNotification",
// fmt.Sprintf(`{"notification": "You have been removed from Lobby #%d"}`, *args.Id))
return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:29,代码来源:lobby.go
示例11: RemoveSpectator
func (lobby *Lobby) RemoveSpectator(player *Player) *helpers.TPError {
err := db.DB.Model(lobby).Association("Spectators").Delete(player).Error
if err != nil {
return helpers.NewTPError(err.Error(), -1)
}
return nil
}
开发者ID:UnnoTed,项目名称:Helen,代码行数:7,代码来源:lobby.go
示例12: ServerVerify
func (Lobby) ServerVerify(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, authority.AuthAction(0), true)
if reqerr != nil {
return reqerr.Encode()
}
var args struct {
Server *string `json:"server"`
Rconpwd *string `json:"rconpwd"`
}
if err := chelpers.GetParams(data, &args); err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
var count int
db.DB.Table("server_records").Where("host = ?", *args.Server).Count(&count)
if count != 0 {
return helpers.NewTPError("A lobby is already using this server.", -1).Encode()
}
info := models.ServerRecord{
Host: *args.Server,
RconPassword: *args.Rconpwd,
}
err := models.VerifyInfo(info)
if err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
return chelpers.EmptySuccessJS
}
开发者ID:demipixel,项目名称:Helen,代码行数:33,代码来源:lobby.go
示例13: PlayerSettingsSet
func (Player) PlayerSettingsSet(so *wsevent.Client, args struct {
Key *string `json:"key"`
Value *string `json:"value"`
}) interface{} {
player, _ := models.GetPlayerBySteamID(chelpers.GetSteamId(so.ID))
err := player.SetSetting(*args.Key, *args.Value)
if err != nil {
return helpers.NewTPErrorFromError(err)
}
switch *args.Key {
case "siteAlias":
profile := models.DecoratePlayerProfileJson(player)
so.EmitJSON(helpers.NewRequest("playerProfile", profile))
if lobbyID, _ := player.GetLobbyID(true); lobbyID != 0 {
lobby, _ := models.GetLobbyByID(lobbyID)
lobbyData := lobby.LobbyData(true)
lobbyData.Send()
}
case "mumbleNick":
if !reMumbleNick.MatchString(*args.Value) {
return helpers.NewTPError("Invalid Mumble nick.", -1)
}
}
return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:30,代码来源:player.go
示例14: PlayerNotReady
func (Player) PlayerNotReady(so *wsevent.Client, _ struct{}) interface{} {
player, tperr := models.GetPlayerBySteamID(chelpers.GetSteamId(so.ID))
if tperr != nil {
return tperr
}
lobbyid, tperr := player.GetLobbyID(false)
if tperr != nil {
return tperr
}
lobby, tperr := models.GetLobbyByID(lobbyid)
if tperr != nil {
return tperr
}
if lobby.State != models.LobbyStateReadyingUp {
return helpers.NewTPError("Lobby hasn't been filled up yet.", 4)
}
tperr = lobby.UnreadyPlayer(player)
lobby.RemovePlayer(player)
hooks.AfterLobbyLeave(lobby, player)
lobby.AddSpectator(player)
hooks.AfterLobbySpec(socket.AuthServer, so, lobby)
if tperr != nil {
return tperr
}
lobby.UnreadyAllPlayers()
return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:34,代码来源:player.go
示例15: AddSpectator
func (lobby *Lobby) AddSpectator(player *Player) *helpers.TPError {
err := db.DB.Model(lobby).Association("Spectators").Append(player).Error
if err != nil {
return helpers.NewTPError(err.Error(), -1)
}
lobby.OnChange(false)
return nil
}
开发者ID:demipixel,项目名称:Helen,代码行数:8,代码来源:lobby.go
示例16: IsPlayerReady
func (lobby *Lobby) IsPlayerReady(player *Player) (bool, *helpers.TPError) {
var ready []bool
err := db.DB.Table("lobby_slots").Where("lobby_id = ? AND player_id = ?", lobby.ID, player.ID).Pluck("ready", &ready).Error
if err != nil {
return false, helpers.NewTPError("Player is not in the lobby.", 5)
}
return (len(ready) != 0 && ready[0]), nil
}
开发者ID:demipixel,项目名称:Helen,代码行数:8,代码来源:lobby.go
示例17: ReadyPlayer
func (lobby *Lobby) ReadyPlayer(player *Player) *helpers.TPError {
err := db.DB.Table("lobby_slots").Where("lobby_id = ? AND player_id = ?", lobby.ID, player.ID).UpdateColumn("ready", true).Error
if err != nil {
return helpers.NewTPError("Player is not in the lobby.", 5)
}
lobby.OnChange(false)
return nil
}
开发者ID:demipixel,项目名称:Helen,代码行数:8,代码来源:lobby.go
示例18: GetPlayerBySteamId
func GetPlayerBySteamId(steamid string) (*Player, *helpers.TPError) {
var player = Player{}
err := db.DB.Where("steam_id = ?", steamid).First(&player).Error
if err != nil {
return nil, helpers.NewTPError("Player is not in the database", -1)
}
return &player, nil
}
开发者ID:N1xx1,项目名称:Helen,代码行数:8,代码来源:player.go
示例19: IsPlayerReady
func (lobby *Lobby) IsPlayerReady(player *Player) (bool, *helpers.TPError) {
slot := &LobbySlot{}
err := db.DB.Where("lobby_id = ? AND player_id = ?", lobby.ID, player.ID).First(slot).Error
if err != nil {
return false, helpers.NewTPError("Player is not in the lobby.", 5)
}
return slot.Ready, nil
}
开发者ID:mcapu,项目名称:Helen,代码行数:8,代码来源:lobby.go
示例20: RemovePlayer
func (lobby *Lobby) RemovePlayer(player *Player) *helpers.TPError {
err := db.DB.Where("player_id = ? AND lobby_id = ?", player.ID, lobby.ID).Delete(&LobbySlot{}).Error
lobby.updateServerAllowedPlayers()
if err != nil {
return helpers.NewTPError(err.Error(), -1)
}
return nil
}
开发者ID:UnnoTed,项目名称:Helen,代码行数:8,代码来源:lobby.go
注:本文中的github.com/TF2Stadium/Helen/helpers.NewTPError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论