public void SetRoomHost(TMContext context) { var info = FindClientInfo(context.Client); HostClient = info; this.HostUser = info.Client.User; }
public async Task <AVUser> LogIn(string username, string password, TMContext context) { Console.WriteLine($"username:{username}, password:{password}"); var user = await AVUser.LogInAsync(username, password); context.Client.User = user; return(user); }
public async Task <TMRoom> CreateRoom(TMRoom room, TMContext context) { await RoomContainer.PostAsync(room); room.UseRpc(this); room.Lobby = this; room.JoinRoom(context); room.SetRoomHost(context); return(room); }
public async Task SetClientStatus(int statusIntValue, TMContext context) { var info = FindClientInfo(context.Client); if (info != null) { info.ClientStatus = (TMClientInfoInRoom.ClientStatusForRoom)statusIntValue; } await context.ReplyOKAsync(); }
public override SlarkContext CreateContext(SlarkClientConnection slarkClientConnection, string message) { var context = new TMContext() { Server = this, Message = CreateMessage(message), Sender = slarkClientConnection, }; return(context); }
public TMClientInfoInRoom QuitRoom(TMContext context) { var info = FindClientInfo(context.Client); ClientInfos.Remove(info); this.RpcAllAsync("OnClientQuit", info); if (ClientInfos.Count == 0) { RoomContainer.ClearRoom(this); } return(info); }
public async Task <TMRoom> QuickJoin(TMContext context) { var room = await RoomContainer.GetQuickStartRoom(); if (room.Status == TMRoom.RoomStatus.Created) { room.UseRpc(this); room.JoinRoom(context); room.Lobby = this; room.SetRoomHost(context); } else { room.JoinRoom(context); } return(room); }
public async Task <TMGame> StartNewGame(TMContext context) { await context.ReplyOKAsync(); var game = new TMGame(); game.Room = this; await game.SaveAsync(); this.Status = RoomStatus.Playing; await this.SaveAsync(); game.UseRpc(Lobby); var players = new List <TMPlayer>(); foreach (var info in this.ClientInfos) { TMPlayer player = new TMPlayer(info) { Game = game }; players.Add(player); } await SaveAllAsync(players); game.Players = players; //List<Task> createdGameTasks = new List<Task>(); //foreach (var p in game.Players) //{ // p.UseRpc(Lobby); // createdGameTasks.Add(this.RpcClientAsync(p.Client, "OnNewGameCreated", game, p)); //} this.RpcAllAsync("OnNewGameCreated", game, game.Players).ContinueWith(t => { game.RpcAllAsync("WaitingForAllottingCharacters"); return(game.InitAllotCharactersAsync()); }).Unwrap(); return(game); }
public TMClientInfoInRoom JoinRoom(TMContext context) { var info = new TMClientInfoInRoom(context.Client) { SeatIndex = NextSeatIndex }; ClientInfos.Add(info); if (Status == RoomStatus.Created) { Status = RoomStatus.Waiting; } info.PropertyChanged += async(sender, e) => { switch (e.PropertyName) { case "ClientStatus": await this.RpcAllAsync("OnClientStatusChanged", context.Client.User.ObjectId, info.SeatIndex, (int)(info.ClientStatus)); break; case "ScreenName": await this.RpcAllAsync("OnScreenNameChanged", context.Client.User.ObjectId, info.ScreenName); break; case "SeatIndex": break; } }; this.RpcAllAsync("OnNewClientJoined", info); return(info); }
public async Task WorldTextMessage(TMClient client, string message, TMContext context) { var clients = this.Connections.Select(c => c.Client as TMClient); await this.RpcAsync(clients, "WorldMessage", client.User, message); }
public async Task RoomTextMessage(string message, TMContext context) { await this.RpcAllAsync("OnRoomTextMessage", context.Client.User, message); }