本文整理匯總了Golang中pkg/config.CherryRooms.GetUserConnection方法的典型用法代碼示例。如果您正苦於以下問題:Golang CherryRooms.GetUserConnection方法的具體用法?Golang CherryRooms.GetUserConnection怎麽用?Golang CherryRooms.GetUserConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pkg/config.CherryRooms
的用法示例。
在下文中一共展示了CherryRooms.GetUserConnection方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RoomMessagePlexer
// RoomMessagePlexer performs all message delivering stuff.
func RoomMessagePlexer(roomName string, rooms *config.CherryRooms) {
preprocessor := html.NewHTMLPreprocessor(rooms)
var allUsers = rooms.GetAllUsersAlias(roomName)
for {
runtime.Gosched()
currMessage := rooms.GetNextMessage(roomName)
if len(currMessage.Say) == 0 && len(currMessage.Image) == 0 /*&& len(currMessage.Sound) == 0*/ {
continue
}
var actionTemplate string
if rooms.HasAction(roomName, currMessage.Action) {
actionTemplate = rooms.GetRoomActionTemplate(roomName, currMessage.Action)
}
if len(actionTemplate) == 0 {
actionTemplate = "<p>({{.hour}}:{{.minute}}:{{.second}}) <b>{{.message-colored-user}}</b>: {{.message-says}}" // INFO(Santiago): A very basic action template.
}
message := preprocessor.ExpandData(roomName, actionTemplate)
if currMessage.Priv != "1" {
rooms.AddPublicMessage(roomName, message)
}
preprocessor.SetDataValue("{{.current-formatted-message}}", message)
messageHighlighted := preprocessor.ExpandData(roomName, rooms.GetHighlightTemplate(roomName))
preprocessor.UnsetDataValue("{{.current-formatted-message}}")
users := rooms.GetRoomUsers(roomName)
for _, user := range users {
if currMessage.Priv == "1" &&
user != currMessage.From &&
user != currMessage.To &&
currMessage.To != allUsers {
continue
}
if rooms.IsIgnored(user, currMessage.From, roomName) {
continue
}
var messageBuffer []byte
if user == currMessage.From ||
user == currMessage.To {
messageBuffer = []byte(messageHighlighted)
} else {
messageBuffer = []byte(message)
}
var conn net.Conn
conn = rooms.GetUserConnection(roomName, user)
if conn == nil {
continue
}
_, e := conn.Write(messageBuffer)
if e != nil {
rooms.EnqueueMessage(roomName, user, "", "", "", rooms.GetExitMessage(roomName), "")
rooms.RemoveUser(roomName, user)
}
}
rooms.DequeueMessage(roomName)
}
}