골롱두지주

8255 단어
프로젝트 주소:
https://github.com/dwg255/landlord
설명:go modules 관리 의존 패키지, 컴파일 자동 다운로드 의존 실행;sqlite 데이터베이스를 사용하면 설정할 필요가 없습니다.스스로 무뇌출패 AI를 가지고 있다.서비스 측은 압력 테스트를 거쳤고 클라이언트 코드는https://github.com/mailgyc/doudizhu, 원본 서버는python tornado로 개발됩니다.Golang이 개발한 서비스 사이드 프로그래밍은 간단하고 실행이 효율적이며 다중 핵 자원을 효과적으로 이용한다. 게임 서버 사이드는 Golang의 전형적인 응용 장면 중 하나이다.프로젝트는goroutine와channel을 대량으로 사용하여 이름과 주석이 명확합니다.
기본 종속 패키지:
  • github.com/astaxie/beego는 주로 그logs 패키지를 사용하고 http 포트 감청 및 처리 요청은 Golang이 자체로 가지고 있는 패키지net/http
  • 를 사용합니다.
  • github.com/mattn/go-sqlite3 지구화 데이터는 sqlite를 사용하여 mysql 설정 및 표 보기 조작을 줄였다
  • github.com/gorilla/websocket websocket 연결 및 메시지 수신
  • 프로젝트 카탈로그 설명:
  • common 공공 가방, * 、 、 *
  • config .go 전역 설정
  • generate.go json 형식의 모든 카드 생성
  • model.go
  • poker.go
  • protocol.go
  • rule.go

  • conf 프로필 디렉터리* 、 、 、 *
  • controllers 컨트롤러 디렉터리* http *
  • Index .go
  • LogiN.go
  • LogoUt.go
  • RegiSter.go

  • db 데이터 디렉터리*sqlite *
  • logs 로그 파일 디렉터리
  • main 프로젝트 입구* 、 *
  • config.go 전역 설정 초기화
  • init.go
  • main.go 시작 서비스, 감청 포트
  • pid
  • roter 라우팅 디렉토리
  • router.go

  • 서비스 논리 디렉터리* 、 、 、 *
  • client.go 클라이언트 요청 처리, 협동 처리 클라이언트 요청 시작
  • request.go
  • robot.go로봇
  • room.go방
  • table.go

  • static 정적 파일 디렉터리
  • templates 템플릿 파일 디렉토리
  • go.mod
  • go.sum
  • LICENSE
  • main.exe 윈도우즈 64비트 시스템에서의 실행 파일
  • README.MD
  • rule.json에서 생성한 모든 카드 파일
  • 코드 예:
    func init() {  	//  pid  ,  pid
    	pidFileName := "pid"
    	fileInfo, err := os.Stat(pidFileName)
    	if err != nil {
    		if os.IsNotExist(err) {
    			err = os.Mkdir(pidFileName, os.ModePerm)
    			fileInfo, _ = os.Stat(pidFileName)
    		}
    	}
    	if fileInfo.IsDir() {
    		pid := os.Getpid()
    		pidFile, err := os.OpenFile(pidFileName+"/landlord.pid", os.O_RDWR|os.O_CREATE, 0766)
    		if err != nil {
    			logs.Error("open pidFile [%s] error :%v", pidFileName, err)
    			return
    		}
    		err = pidFile.Truncate(0)  //    
    
    		_, err = io.WriteString(pidFile, strconv.Itoa(pid))
    		if err != nil {
    			logs.Error("write pid error :%v", err)
    		}
    
    		err = pidFile.Close()
    		if err != nil {
    			logs.Error("close pid file err: %v", err)
    		}
    	} else {
    		logs.Error("pidFile [%s] is exists and not dir", pidFileName)
    	}
    }
    

    * 추가 코드는 GitHub * -service-room을 참조하십시오.go 파일에는 압력 측정 코드가 포함되어 있으며 5000개의 방의 CPU 평균 점유율은 30%-50%이고 메모리는 200M 정도이다.
    실행 단계:
    1. 원본 다운로드:
    git clone https://github.com/dwg255/landlord.git
    

    2. 컴파일링:
    cd landlord/main
    go build -o ../main.exe
    cd ..
    main.exe
    

    3. 시작: 브라우저 액세스http://localhost
    4. 효과 표시:http://blzz.shop
    5. 캡처 실행:
    License
    This project is released under the terms of the MIT license. See LICENSE for more information or see https://opensource.org/licenses/MIT.

    좋은 웹페이지 즐겨찾기