当前位置: 首页>>代码示例>>Golang>>正文


Golang config.CherryRooms类代码示例

本文整理汇总了Golang中pkg/config.CherryRooms的典型用法代码示例。如果您正苦于以下问题:Golang CherryRooms类的具体用法?Golang CherryRooms怎么用?Golang CherryRooms使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CherryRooms类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: PubHandle

// PubHandle implements the handle for the room's public directory (GET).
func PubHandle(newConn net.Conn, roomName, httpPayload string, rooms *config.CherryRooms, preprocessor *html.Preprocessor) {
	pubdir := rooms.GetPublicDirectory(roomName)
	var httpReq string
	var spaceNr int
	for _, h := range httpPayload {
		if h == ' ' {
			spaceNr++
		}
		if h == '\n' || h == '\r' || spaceNr > 1 {
			break
		}
		httpReq += string(h)
	}
	var replyBuffer []byte
	if len(pubdir) == 0 || !strings.HasPrefix(httpReq, "GET /pub/"+pubdir) {
		replyBuffer = rawhttp.MakeReplyBuffer(html.GetBadAssErrorData(), 404, true)
	} else {
		relativeLocalPath := httpReq[9:]
		_, err := os.Stat(relativeLocalPath)
		if os.IsNotExist(err) {
			replyBuffer = rawhttp.MakeReplyBuffer(html.GetBadAssErrorData(), 404, true)
		} else {
			replyBuffer = rawhttp.MakeReplyBufferByFilePath(relativeLocalPath, 200, true)
		}
	}
	newConn.Write(replyBuffer)
	newConn.Close()
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:29,代码来源:reqtraps.go

示例2: GetJoinHandle

// GetJoinHandle implements the handle for the join document (GET).
func GetJoinHandle(newConn net.Conn, roomName, httpPayload string, rooms *config.CherryRooms, preprocessor *html.Preprocessor) {
	//  INFO(Santiago): The form for room joining was requested, so we will flush it to client.
	var replyBuffer []byte
	replyBuffer = rawhttp.MakeReplyBuffer(preprocessor.ExpandData(roomName, rooms.GetEntranceTemplate(roomName)), 200, true)
	newConn.Write(replyBuffer)
	newConn.Close()
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:8,代码来源:reqtraps.go

示例3: GetRoomTemplates

// GetRoomTemplates parses "cherry.[roomName].templates" section.
func GetRoomTemplates(roomName string, cherryRooms *config.CherryRooms, configData, filepath string) *CherryFileError {
	var data string
	var line int
	var err *CherryFileError
	data, _, line, err = GetDataFromSection("cherry."+roomName+".templates",
		configData, 1, filepath)
	if err != nil {
		return err
	}
	var set []string
	set, line, data = GetNextSetFromData(data, line, "=")
	for len(set) == 2 {
		if cherryRooms.HasTemplate(roomName, set[0]) {
			return NewCherryFileError(filepath, line, "room template \""+set[0]+"\" redeclared.")
		}
		if len(set[1]) == 0 {
			return NewCherryFileError(filepath, line, "room template with no value.")
		}
		if set[1][0] != '"' || set[1][len(set[1])-1] != '"' {
			return NewCherryFileError(filepath, line, "room template must be set with a valid string.")
		}
		var templateData []byte
		var templateDataErr error
		templateData, templateDataErr = ioutil.ReadFile(set[1][1 : len(set[1])-1])
		if templateDataErr != nil {
			return NewCherryFileError(filepath, line, "unable to access room template file [more details: "+templateDataErr.Error()+"].")
		}
		cherryRooms.AddTemplate(roomName, set[0], string(templateData))
		set, line, data = GetNextSetFromData(data, line, "=")
	}
	return nil
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:33,代码来源:parser.go

示例4: GetBriefHandle

// GetBriefHandle implements the handle for the brief document (GET).
func GetBriefHandle(newConn net.Conn, roomName, httpPayload string, rooms *config.CherryRooms, preprocessor *html.Preprocessor) {
	var replyBuffer []byte
	if rooms.IsAllowingBriefs(roomName) {
		replyBuffer = rawhttp.MakeReplyBuffer(preprocessor.ExpandData(roomName, rooms.GetBriefTemplate(roomName)), 200, true)
	} else {
		replyBuffer = rawhttp.MakeReplyBuffer(html.GetBadAssErrorData(), 404, true)
	}
	newConn.Write(replyBuffer)
	newConn.Close()
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:11,代码来源:reqtraps.go

示例5: roomImageMainVerifier

func roomImageMainVerifier(mSet, sSet []string, mLine, sLine int, roomName, filepath string, cherryRooms *config.CherryRooms) *CherryFileError {
	if cherryRooms.HasImage(roomName, mSet[0]) {
		return NewCherryFileError(filepath, mLine, "room image \""+mSet[0]+"\" redeclared.")
	}
	if len(mSet[1]) == 0 {
		return NewCherryFileError(filepath, mLine, "unlabeled room image.")
	}
	if mSet[1][0] != '"' || mSet[1][len(mSet[1])-1] != '"' {
		return NewCherryFileError(filepath, mLine, "room image must be set with a valid string.")
	}
	return nil
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:12,代码来源:parser.go

示例6: GetTopHandle

// GetTopHandle implements the handle for the top document (GET).
func GetTopHandle(newConn net.Conn, roomName, httpPayload string, rooms *config.CherryRooms, preprocessor *html.Preprocessor) {
	var userData map[string]string
	userData = rawhttp.GetFieldsFromGet(httpPayload)
	var replyBuffer []byte
	if !rooms.IsValidUserRequest(roomName, userData["user"], userData["id"], newConn) {
		replyBuffer = rawhttp.MakeReplyBuffer(html.GetBadAssErrorData(), 404, true)
	} else {
		replyBuffer = rawhttp.MakeReplyBuffer(preprocessor.ExpandData(roomName, rooms.GetTopTemplate(roomName)), 200, true)
	}
	newConn.Write(replyBuffer)
	newConn.Close()
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:13,代码来源:reqtraps.go

示例7: GetExitHandle

// GetExitHandle implements the handle for the exit document (GET).
func GetExitHandle(newConn net.Conn, roomName, httpPayload string, rooms *config.CherryRooms, preprocessor *html.Preprocessor) {
	var userData map[string]string
	var replyBuffer []byte
	userData = rawhttp.GetFieldsFromGet(httpPayload)
	if !rooms.IsValidUserRequest(roomName, userData["user"], userData["id"], newConn) {
		replyBuffer = rawhttp.MakeReplyBuffer(html.GetBadAssErrorData(), 404, true)
	} else {
		preprocessor.SetDataValue("{{.nickname}}", userData["user"])
		preprocessor.SetDataValue("{{.session-id}}", userData["id"])
		replyBuffer = rawhttp.MakeReplyBuffer(preprocessor.ExpandData(roomName, rooms.GetExitTemplate(roomName)), 200, true)
	}
	rooms.EnqueueMessage(roomName, userData["user"], "", "", "", rooms.GetExitMessage(roomName), "")
	newConn.Write(replyBuffer)
	rooms.RemoveUser(roomName, userData["user"])
	newConn.Close()
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:17,代码来源:reqtraps.go

示例8: openRooms

func openRooms(configPath string) {
	var cherryRooms *config.CherryRooms
	var err *parser.CherryFileError
	cherryRooms, err = parser.ParseCherryFile(configPath)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		rooms := cherryRooms.GetRooms()
		for _, r := range rooms {
			go messageplexer.RoomMessagePlexer(r, cherryRooms)
			go peer(r, cherryRooms)
		}
	}
	sigintWatchdog := make(chan os.Signal, 1)
	signal.Notify(sigintWatchdog, os.Interrupt)
	signal.Notify(sigintWatchdog, syscall.SIGINT|syscall.SIGTERM)
	<-sigintWatchdog
	cleanup()
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:20,代码来源:cherry.go

示例9: peer

func peer(roomName string, c *config.CherryRooms) {
	port := c.GetListenPort(roomName)
	var portNum int64
	portNum, _ = strconv.ParseInt(port, 10, 16)
	var err error
	var room *config.RoomConfig
	room = c.GetRoomByPort(int16(portNum))
	//room.MainPeer, err = net.Listen("tcp", c.GetServerName()+":"+port)
	room.MainPeer, err = getListenPeer(c, port)
	if err != nil {
		fmt.Println("ERROR: " + err.Error())
		os.Exit(1)
	}
	defer room.MainPeer.Close()
	for {
		conn, err := room.MainPeer.Accept()
		if err != nil {
			fmt.Println(err.Error())
			continue
		}
		go processNewConnection(conn, roomName, c)
	}
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:23,代码来源:cherry.go

示例10: setMaxUsers

func setMaxUsers(cherryRooms *config.CherryRooms, roomName, value string) {
	var intValue int64
	intValue, _ = strconv.ParseInt(value, 10, 64)
	cherryRooms.SetMaxUsers(roomName, int(intValue))
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:5,代码来源:parser.go

示例11: setPrivateMessageMarker

func setPrivateMessageMarker(cherryRooms *config.CherryRooms, roomName, marker string) {
	cherryRooms.SetPrivateMessageMarker(roomName, marker[1:len(marker)-1])
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:3,代码来源:parser.go

示例12: setGreetingMessage

func setGreetingMessage(cherryRooms *config.CherryRooms, roomName, message string) {
	cherryRooms.SetGreetingMessage(roomName, message[1:len(message)-1])
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:3,代码来源:parser.go

示例13: setOnDeIgnoreMessage

func setOnDeIgnoreMessage(cherryRooms *config.CherryRooms, roomName, message string) {
	cherryRooms.SetOnDeIgnoreMessage(roomName, message[1:len(message)-1])
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:3,代码来源:parser.go

示例14: setDeIgnoreAction

func setDeIgnoreAction(cherryRooms *config.CherryRooms, roomName, action string) {
	cherryRooms.SetDeIgnoreAction(roomName, action[1:len(action)-1])
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:3,代码来源:parser.go

示例15: getListenPeer

func getListenPeer(c *config.CherryRooms, port string) (net.Listener, error) {
	var listenConn net.Listener
	var listenError error
	if c.GetCertificatePath() != "" && c.GetPrivateKeyPath() != "" {
		cert, err := tls.LoadX509KeyPair(c.GetCertificatePath(), c.GetPrivateKeyPath())
		if err != nil {
			return nil, err
		}
		secParams := &tls.Config{Certificates: []tls.Certificate{cert}}
		listenConn, listenError = tls.Listen("tcp", c.GetServerName()+":"+port, secParams)
	} else {
		listenConn, listenError = net.Listen("tcp", c.GetServerName()+":"+port)
	}
	return listenConn, listenError
}
开发者ID:rafael-santiago,项目名称:cherry,代码行数:15,代码来源:cherry.go


注:本文中的pkg/config.CherryRooms类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。