Return updated state object
Return error when player exists in dictionary Modifications to list call Debug RPC method Debug RPC method -S Include client changes
This commit is contained in:
		
							
								
								
									
										1
									
								
								client/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								client/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					builds
 | 
				
			||||||
@ -6,6 +6,7 @@ const SERVER_ENDPOINT := "nakama.cloudsumu.com"
 | 
				
			|||||||
var _session : NakamaSession
 | 
					var _session : NakamaSession
 | 
				
			||||||
var _client : NakamaClient = Nakama.create_client(KEY, SERVER_ENDPOINT, 7350, "http")
 | 
					var _client : NakamaClient = Nakama.create_client(KEY, SERVER_ENDPOINT, 7350, "http")
 | 
				
			||||||
var _socket : NakamaSocket
 | 
					var _socket : NakamaSocket
 | 
				
			||||||
 | 
					var _precenses : Dictionary = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func authenticate_async(email : String, password : String) -> NakamaException:
 | 
					func authenticate_async(email : String, password : String) -> NakamaException:
 | 
				
			||||||
	var result : NakamaException = null
 | 
						var result : NakamaException = null
 | 
				
			||||||
@ -44,9 +45,18 @@ func join_world_async() -> Dictionary:
 | 
				
			|||||||
	if world.is_exception():
 | 
						if world.is_exception():
 | 
				
			||||||
		print("Join world error occured: %s" % world.exception.message)
 | 
							print("Join world error occured: %s" % world.exception.message)
 | 
				
			||||||
		return {}
 | 
							return {}
 | 
				
			||||||
	var _world_id : String = world.payload
 | 
							
 | 
				
			||||||
	print(_world_id)
 | 
						var match_join_result : NakamaRTAPI.Match = yield(_socket.join_match_async(world.payload), "completed")
 | 
				
			||||||
	return {}
 | 
						if match_join_result.is_exception():
 | 
				
			||||||
 | 
							print("Join match error: %s - %s" % [match_join_result.exception.status_code, match_join_result.exception.message])
 | 
				
			||||||
 | 
							return {}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						for precense in match_join_result.presences:
 | 
				
			||||||
 | 
							_precenses[precense.user_id] = precense
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						print("Currently connected: %s" % _precenses.size())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return _precenses
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _on_socket_closed():
 | 
					func _on_socket_closed():
 | 
				
			||||||
	_socket = null
 | 
						_socket = null
 | 
				
			||||||
 | 
				
			|||||||
@ -36,9 +36,9 @@ func (m *Match) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB
 | 
				
			|||||||
func (m *Match) MatchJoinAttempt(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, presence runtime.Presence, metadata map[string]string) (interface{}, bool, string) {
 | 
					func (m *Match) MatchJoinAttempt(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, presence runtime.Presence, metadata map[string]string) (interface{}, bool, string) {
 | 
				
			||||||
	mState, _ := state.(*MatchState)
 | 
						mState, _ := state.(*MatchState)
 | 
				
			||||||
	if _, ok := mState.presences[presence.GetUserId()]; ok {
 | 
						if _, ok := mState.presences[presence.GetUserId()]; ok {
 | 
				
			||||||
		return mState, true, ""
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return mState, false, "User already logged in."
 | 
							return mState, false, "User already logged in."
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return mState, true, ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -48,7 +48,7 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB
 | 
				
			|||||||
	for _, precense := range presences {
 | 
						for _, precense := range presences {
 | 
				
			||||||
		mState.presences[precense.GetUserId()] = precense
 | 
							mState.presences[precense.GetUserId()] = precense
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return state
 | 
						return mState
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *Match) MatchLeave(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, presences []runtime.Presence) interface{} {
 | 
					func (m *Match) MatchLeave(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, presences []runtime.Presence) interface{} {
 | 
				
			||||||
@ -56,7 +56,7 @@ func (m *Match) MatchLeave(ctx context.Context, logger runtime.Logger, db *sql.D
 | 
				
			|||||||
	for _, presence := range presences {
 | 
						for _, presence := range presences {
 | 
				
			||||||
		delete(mState.presences, presence.GetUserId())
 | 
							delete(mState.presences, presence.GetUserId())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return state
 | 
						return mState
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *Match) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, messages []runtime.MatchData) interface{} {
 | 
					func (m *Match) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, messages []runtime.MatchData) interface{} {
 | 
				
			||||||
 | 
				
			|||||||
@ -11,37 +11,41 @@ func getFirstWorld(ctx context.Context, logger runtime.Logger, nk runtime.Nakama
 | 
				
			|||||||
	// List existing matches
 | 
						// List existing matches
 | 
				
			||||||
	// that have been 1 & 4 players
 | 
						// that have been 1 & 4 players
 | 
				
			||||||
	minSize := 1
 | 
						minSize := 1
 | 
				
			||||||
	maxSize := 4
 | 
						maxSize := 31
 | 
				
			||||||
	matches, listErr := nk.MatchList(ctx, 1, false, "", &minSize, &maxSize, "") //local matches = nakama.match_list()
 | 
						//5, false, "", &minSize, &maxSize, ""
 | 
				
			||||||
 | 
						if matches, err := nk.MatchList(ctx, 1, true, "", &minSize, &maxSize, ""); err != nil {
 | 
				
			||||||
	// Return if listing error
 | 
							logger.Printf("Failed to list matches when grabing first world! Error: %v\n", err)
 | 
				
			||||||
	if listErr != nil {
 | 
							return "", err
 | 
				
			||||||
		logger.Printf("Failed to list matches when grabing first world! Error: %v\n", listErr)
 | 
					 | 
				
			||||||
		return "", listErr
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// If no matches exist, create one
 | 
					 | 
				
			||||||
	if len(matches) <= 0 {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Create match
 | 
					 | 
				
			||||||
		//params := map[string]interface{}{}
 | 
					 | 
				
			||||||
		matchID, createErr := nk.MatchCreate(ctx, "control", map[string]interface{}{})
 | 
					 | 
				
			||||||
		//return nakama.match_create("world_control", {})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Return if creation error
 | 
					 | 
				
			||||||
		if createErr != nil {
 | 
					 | 
				
			||||||
			logger.Printf("Failed to create match when grabing first world! Error: %v\n", createErr)
 | 
					 | 
				
			||||||
			return "", createErr
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		logger.Info("Successfully created new match!")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Return newly created match
 | 
					 | 
				
			||||||
		return matchID, nil
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Return first found match
 | 
							//For debug purposes
 | 
				
			||||||
		return matches[0].GetMatchId(), nil
 | 
							for _, match := range matches {
 | 
				
			||||||
 | 
								logger.Info("Found match with id: %s", match.GetMatchId())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// If no matches exist, create one
 | 
				
			||||||
 | 
							if len(matches) <= 0 {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Create match
 | 
				
			||||||
 | 
								//params := map[string]interface{}{}
 | 
				
			||||||
 | 
								matchID, createErr := nk.MatchCreate(ctx, "control", map[string]interface{}{})
 | 
				
			||||||
 | 
								//return nakama.match_create("world_control", {})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Return if creation error
 | 
				
			||||||
 | 
								if createErr != nil {
 | 
				
			||||||
 | 
									logger.Printf("Failed to create match when grabing first world! Error: %v\n", createErr)
 | 
				
			||||||
 | 
									return "", createErr
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								logger.Info("Successfully created new match!")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Return newly created match
 | 
				
			||||||
 | 
								return matchID, nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Return first found match
 | 
				
			||||||
 | 
								return matches[0].GetMatchId(), nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user