public override GameState GetMessage(MjsonMessageAll msgobj) { if ((msgobj.type == MsgType.NONE) || (msgobj.type == MsgType.PON) || (msgobj.type == MsgType.DAIMINKAN) || (msgobj.type == MsgType.CHI) || (msgobj.type == MsgType.HORA)) { getMsgList.Add(msgobj); if (getMsgList.Count == Constants.PLAYER_NUM) { if (getMsgList.Count(e => e.IsHORA()) > 0) { var horaObj = GetNearestHoraPlayerMsg(getMsgList); serverController.Hora(horaObj.actor, horaObj.target, horaObj.pai); getMsgList.Dispose(); return(new AfterHoraState(this)); } serverController.ReachAccept(); return(new AfterReachAccceptState(this, getMsgList)); } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return(this); }
public override GameState GetMessage(MjsonMessageAll msgobj) { if ((msgobj.IsDAHAI()) || (msgobj.IsNONE())) { getMsgList.Add(msgobj); if (getMsgList.Count(e => e.IsDAHAI()) == 1 && getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM - 1) { var dahaiObj = getMsgList.First(e => e.IsDAHAI()); serverController.Dahai(dahaiObj.actor, dahaiObj.pai, dahaiObj.tsumogiri); getMsgList.Dispose(); return(new AfterReachDahaiState(this)); } if ((getMsgList.Count == Constants.PLAYER_NUM)) { serverController.SendErrorToRoomMember(msgobj); } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return(this); }
public override GameState GetMessage(MjsonMessageAll msgobj) { if (msgobj.IsNONE()) { getMsgList.Add(msgobj); if ((getMsgList.Count == Constants.PLAYER_NUM)) { if (serverController.CanEndGame()) { serverController.SendEndgame(); return(new EndState(this)); } else { serverController.StartKyoku(); return(new AfterStartKyokuState(this)); } } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return(this); }
public override GameState GetMessage(MjsonMessageAll msgobj) { if (msgobj.IsNONE()) { getMsgList.Add(msgobj); if (getMsgList.Count < Constants.PLAYER_NUM) { return(this); } //受け継いだメッセージ内に4人共アクションがない場合 if (prevMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM) { //終局判定 if (serverController.CanFinishKyoku()) { serverController.Ryukyoku(); getMsgList.Dispose(); return(new AfterRyukyokuState(this)); } else { //ツモ状態へ移行 serverController.Tsumo(); return(new AfterTsumoState(this)); } } //hora else if (prevMsgList.Count(e => e.IsDAIMINKAN()) == 1) { var daiminkanObj = prevMsgList.First(e => e.IsDAIMINKAN()); serverController.Daiminkan(daiminkanObj.actor, daiminkanObj.target, daiminkanObj.pai, daiminkanObj.consumed); prevMsgList.Dispose(); return(new AfterKanState(this)); } else if (prevMsgList.Count(e => e.IsPON()) == 1) { var ponObj = prevMsgList.First(e => e.IsPON()); serverController.Pon(ponObj.actor, ponObj.target, ponObj.pai, ponObj.consumed); prevMsgList.Dispose(); return(new AfterTsumoState(this)); } else if (prevMsgList.Count(e => e.IsCHI()) == 1) { var chiObj = prevMsgList.First(e => e.IsCHI()); serverController.Chi(chiObj.actor, chiObj.target, chiObj.pai, chiObj.consumed); prevMsgList.Dispose(); return(new AfterTsumoState(this)); } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return(this); }
//ここからメッセージを送信するための関数 //モデル操作完了後に呼び出される。 public void SendErrorToRoomMember(MjsonMessageAll msgobj) { var errorMsg = JsonConvert.SerializeObject(msgobj); foreach (var clientName in playerNames) { serverRouter.SendErrorToClient(clientName, errorMsg); } }
public override GameState GetMessage(MjsonMessageAll msgobj) { if (msgobj.type == MsgType.JOIN) { getMsgList.Add(msgobj); if ((getMsgList.Count == Constants.PLAYER_NUM)) { serverController.StartGame(); return(new AfterStartGameState(this)); } } else { serverController.SendErrorToRoomMember(msgobj); } return(this); }
public override GameState GetMessage(MjsonMessageAll msgobj) { if (msgobj.type == MsgType.JOIN) { getMsgList.Add(msgobj); if ((getMsgList.Count == Constants.PLAYER_NUM)) { serverController.StartGame(); return new AfterStartGameState(this); } } else { serverController.SendErrorToRoomMember(msgobj); } return this; }
public override GameState GetMessage(MjsonMessageAll msgobj) { if (msgobj.type == MsgType.NONE) { getMsgList.Add(msgobj); if ((getMsgList.Count == Constants.PLAYER_NUM)) { serverController.Tsumo(); getMsgList.Dispose(); return(new AfterTsumoState(this)); } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return(this); }
//ここからメッセージを受け取った際の状態遷移関数 public void GetMessage(MjsonMessageAll msgobj) { serverState = serverState.GetMessage(msgobj); }
public void GetJoin(MjsonMessageAll msgobj) { serverController.Join(msgobj.name); serverState = serverState.GetMessage(msgobj); }
public override GameState GetMessage(MjsonMessageAll msgobj) { if ((msgobj.type == MsgType.NONE) || (msgobj.type == MsgType.PON) || (msgobj.type == MsgType.DAIMINKAN) || (msgobj.type == MsgType.CHI) || (msgobj.type == MsgType.HORA)) { getMsgList.Add(msgobj); if (getMsgList.Count == Constants.PLAYER_NUM) { //4人共アクションがない場合 if (getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM) { //終局判定 if (serverController.CanFinishKyoku()) { serverController.Ryukyoku(); getMsgList.Dispose(); return(new AfterRyukyokuState(this)); } else { //ツモ状態へ移行 serverController.Tsumo(); return(new AfterTsumoState(this)); } } //以下実装予定 //hora else if (getMsgList.Count(e => e.IsHORA()) >= 1) { //頭ハネ var horaObj = GetNearestHoraPlayerMsg(getMsgList); serverController.Hora(horaObj.actor, horaObj.target, horaObj.pai); getMsgList.Dispose(); return(new AfterHoraState(this)); } else if (getMsgList.Count(e => e.IsDAIMINKAN()) == 1) { var daiminkanObj = getMsgList.First(e => e.IsDAIMINKAN()); serverController.Daiminkan(daiminkanObj.actor, daiminkanObj.target, daiminkanObj.pai, daiminkanObj.consumed); getMsgList.Dispose(); return(new AfterKanState(this)); } else if (getMsgList.Count(e => e.IsPON()) == 1) { var ponObj = getMsgList.First(e => e.IsPON()); serverController.Pon(ponObj.actor, ponObj.target, ponObj.pai, ponObj.consumed); getMsgList.Dispose(); return(new AfterTsumoState(this)); } else if (getMsgList.Count(e => e.IsCHI()) == 1) { var chiObj = getMsgList.First(e => e.IsCHI()); serverController.Chi(chiObj.actor, chiObj.target, chiObj.pai, chiObj.consumed); getMsgList.Dispose(); return(new AfterTsumoState(this)); } } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return(this); }
public override GameState GetMessage(MjsonMessageAll msgobj) { if ((msgobj.IsDAHAI()) || (msgobj.IsREACH()) || (msgobj.IsANKAN()) || (msgobj.IsKAKAN()) || (msgobj.IsHORA()) || (msgobj.IsNONE())) { getMsgList.Add(msgobj); if (getMsgList.Count == Constants.PLAYER_NUM) { // if (getMsgList.Count(e => e.IsHORA()) >= 1 ) { var horaObj = GetNearestHoraPlayerMsg(getMsgList); serverController.Hora(horaObj.actor, horaObj.target, horaObj.pai); getMsgList.Dispose(); return new AfterHoraState(this); } //RinshanFlggOff //serverController.ResetRinshanFlag(); //serverController.ResetIppatsuFlag(); if (getMsgList.Count(e => e.IsDAHAI()) == 1 && getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM - 1) { var dahaiObj = getMsgList.Where(e => e.IsDAHAI()) .First(); serverController.Dahai(dahaiObj.actor, dahaiObj.pai, dahaiObj.tsumogiri); getMsgList.Dispose(); return new AfterDahaiState(this); } else if (getMsgList.Count(e => e.IsREACH()) == 1 && getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM - 1) { var reachObj = getMsgList.First(e => e.IsREACH()); serverController.Reach(reachObj.actor); getMsgList.Dispose(); return new AfterReachState(this); } else if (getMsgList.Count(e => e.IsANKAN()) == 1 && getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM - 1) { var kanObj = getMsgList.First(e => e.IsREACH()); serverController.Ankan(kanObj.actor, kanObj.target, kanObj.pai, kanObj.consumed); getMsgList.Dispose(); return new AfterKanState(this); } } } else { //error handling serverController.SendErrorToRoomMember(msgobj); } return this; }
public virtual GameState GetMessage(MjsonMessageAll msgobj) { return(this); }
public override GameState GetMessage(MjsonMessageAll msgobj) { if ((msgobj.IsDAHAI()) || (msgobj.IsREACH()) || (msgobj.IsANKAN()) || (msgobj.IsKAKAN()) || (msgobj.IsHORA()) || (msgobj.IsNONE())) { getMsgList.Add(msgobj); if (getMsgList.Count == Constants.PLAYER_NUM) { // if (getMsgList.Count(e => e.IsHORA()) >= 1) { var horaObj = GetNearestHoraPlayerMsg(getMsgList); serverController.Hora(horaObj.actor, horaObj.target, horaObj.pai); getMsgList.Dispose(); return(new AfterHoraState(this)); } //RinshanFlggOff //serverController.ResetRinshanFlag(); //serverController.ResetIppatsuFlag(); if (getMsgList.Count(e => e.IsDAHAI()) == 1 && getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM - 1) { var dahaiObj = getMsgList.Where(e => e.IsDAHAI()) .First(); serverController.Dahai(dahaiObj.actor, dahaiObj.pai, dahaiObj.tsumogiri); getMsgList.Dispose(); return(new AfterDahaiState(this)); } else if (getMsgList.Count(e => e.IsREACH()) == 1 && getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM - 1) { var reachObj = getMsgList.First(e => e.IsREACH()); serverController.Reach(reachObj.actor); getMsgList.Dispose(); return(new AfterReachState(this)); } else if (getMsgList.Count(e => e.IsANKAN()) == 1 && getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM - 1) { var kanObj = getMsgList.First(e => e.IsREACH()); serverController.Ankan(kanObj.actor, kanObj.target, kanObj.pai, kanObj.consumed); getMsgList.Dispose(); return(new AfterKanState(this)); } } } else { //error handling serverController.SendErrorToRoomMember(msgobj); } return(this); }
public override GameState GetMessage(MjsonMessageAll msgobj) { if (msgobj.type == MsgType.NONE) { getMsgList.Add(msgobj); if ((getMsgList.Count == Constants.PLAYER_NUM)) { serverController.Tsumo(); getMsgList.Dispose(); return new AfterTsumoState(this); } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return this; }
public virtual GameState GetMessage(MjsonMessageAll msgobj) { return this; }
public override GameState GetMessage(MjsonMessageAll msgobj) { return this; }
public override GameState GetMessage(MjsonMessageAll msgobj) { return(this); }
public override GameState GetMessage(MjsonMessageAll msgobj) { if ((msgobj.type == MsgType.NONE) || (msgobj.type == MsgType.PON) || (msgobj.type == MsgType.DAIMINKAN) || (msgobj.type == MsgType.CHI) || (msgobj.type == MsgType.HORA)) { getMsgList.Add(msgobj); if (getMsgList.Count == Constants.PLAYER_NUM) { if(getMsgList.Count(e => e.IsHORA()) > 0) { var horaObj = GetNearestHoraPlayerMsg(getMsgList); serverController.Hora(horaObj.actor, horaObj.target, horaObj.pai); getMsgList.Dispose(); return new AfterHoraState(this); } serverController.ReachAccept(); return new AfterReachAccceptState(this, getMsgList); } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return this; }
public override GameState GetMessage(MjsonMessageAll msgobj) { if ((msgobj.IsDAHAI()) || (msgobj.IsNONE())) { getMsgList.Add(msgobj); if (getMsgList.Count(e => e.IsDAHAI()) == 1 && getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM - 1) { var dahaiObj = getMsgList.First(e => e.IsDAHAI()); serverController.Dahai(dahaiObj.actor, dahaiObj.pai, dahaiObj.tsumogiri); getMsgList.Dispose(); return new AfterReachDahaiState(this); } if ((getMsgList.Count == Constants.PLAYER_NUM)) { serverController.SendErrorToRoomMember(msgobj); } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return this; }
//受信メッセージルーティング処理 public async void RouteGetMessage(TcpClient client, string message) { await semaphore.WaitAsync(); try { MjsonMessageAll msgobj = JsonConvert.DeserializeObject <MjsonMessageAll>(message); if (IsValidMessageType(msgobj.type) == false) { SendErrorToClient(client, message); return; } switch (msgobj.type) { case MsgType.JOIN: //roomがない場合room作成 if (!roomNameServerDictionary.ContainsKey(msgobj.room)) { roomNameServerDictionary.Add(msgobj.room, new GameContext(this, msgobj.room)); } //参加人数が上限に達していないかチェック if (roomNameServerDictionary[msgobj.room].CanJoin()) { Console.WriteLine("{0} Join at {1}", msgobj.name, msgobj.room); clientNameRoomDictionary.Add(msgobj.name, msgobj.room); clientNameTcpClientDictionary.Add(msgobj.name, client); //Join実行中にクライアント名をキーにしてクライアントを探索するので、 //Join実行前にクライアントをclientNameTcpClientDictionaryへ登録する必要あり。 roomNameServerDictionary[msgobj.room].GetJoin(msgobj); } else { Console.WriteLine("Can't Join at {0}", msgobj.room); } break; default: var clientName = clientNameTcpClientDictionary.FirstOrDefault(e => e.Value == client).Key; if (clientName == null) { break; } var roomName = clientNameRoomDictionary[clientName]; if (roomName == null) { SendErrorToClient(client, message); } else { roomNameServerDictionary[roomName].GetMessage(msgobj); } break; } } catch (Exception e) { DebugUtil.ServerDebug(e.Message); } finally { semaphore.Release(); } }
public override GameState GetMessage(MjsonMessageAll msgobj) { if (msgobj.IsNONE()) { getMsgList.Add(msgobj); if(getMsgList.Count < Constants.PLAYER_NUM) { return this; } //受け継いだメッセージ内に4人共アクションがない場合 if (prevMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM) { //終局判定 if (serverController.CanFinishKyoku()) { serverController.Ryukyoku(); getMsgList.Dispose(); return new AfterRyukyokuState(this); } else { //ツモ状態へ移行 serverController.Tsumo(); return new AfterTsumoState(this); } } //hora else if (prevMsgList.Count(e => e.IsDAIMINKAN()) == 1) { var daiminkanObj = prevMsgList.First(e => e.IsDAIMINKAN()); serverController.Daiminkan(daiminkanObj.actor, daiminkanObj.target, daiminkanObj.pai, daiminkanObj.consumed); prevMsgList.Dispose(); return new AfterKanState(this); } else if (prevMsgList.Count(e => e.IsPON()) == 1) { var ponObj = prevMsgList.First(e => e.IsPON()); serverController.Pon(ponObj.actor, ponObj.target, ponObj.pai, ponObj.consumed); prevMsgList.Dispose(); return new AfterTsumoState(this); } else if (prevMsgList.Count(e => e.IsCHI()) == 1) { var chiObj = prevMsgList.First(e => e.IsCHI()); serverController.Chi(chiObj.actor, chiObj.target, chiObj.pai, chiObj.consumed); prevMsgList.Dispose(); return new AfterTsumoState(this); } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return this; }
public override GameState GetMessage(MjsonMessageAll msgobj) { if ((msgobj.type == MsgType.NONE) || (msgobj.type == MsgType.PON) || (msgobj.type == MsgType.DAIMINKAN) || (msgobj.type == MsgType.CHI) || (msgobj.type == MsgType.HORA)) { getMsgList.Add(msgobj); if (getMsgList.Count == Constants.PLAYER_NUM) { //4人共アクションがない場合 if (getMsgList.Count(e => e.IsNONE()) == Constants.PLAYER_NUM) { //終局判定 if (serverController.CanFinishKyoku()) { serverController.Ryukyoku(); getMsgList.Dispose(); return new AfterRyukyokuState(this); } else { //ツモ状態へ移行 serverController.Tsumo(); return new AfterTsumoState(this); } } //以下実装予定 //hora else if (getMsgList.Count(e => e.IsHORA()) >= 1) { //頭ハネ var horaObj = GetNearestHoraPlayerMsg(getMsgList); serverController.Hora(horaObj.actor, horaObj.target, horaObj.pai); getMsgList.Dispose(); return new AfterHoraState(this); } else if (getMsgList.Count(e => e.IsDAIMINKAN()) == 1) { var daiminkanObj = getMsgList.First(e => e.IsDAIMINKAN()); serverController.Daiminkan(daiminkanObj.actor, daiminkanObj.target, daiminkanObj.pai, daiminkanObj.consumed); getMsgList.Dispose(); return new AfterKanState(this); } else if (getMsgList.Count(e => e.IsPON()) == 1) { var ponObj = getMsgList.First(e => e.IsPON()); serverController.Pon(ponObj.actor, ponObj.target, ponObj.pai, ponObj.consumed); getMsgList.Dispose(); return new AfterTsumoState(this); } else if (getMsgList.Count(e => e.IsCHI()) == 1) { var chiObj = getMsgList.First(e => e.IsCHI()); serverController.Chi(chiObj.actor, chiObj.target, chiObj.pai, chiObj.consumed); getMsgList.Dispose(); return new AfterTsumoState(this); } } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return this; }
public override GameState GetMessage(MjsonMessageAll msgobj) { if (msgobj.IsNONE()) { getMsgList.Add(msgobj); if ((getMsgList.Count == Constants.PLAYER_NUM)) { if (serverController.CanEndGame()) { serverController.SendEndgame(); return new EndState(this); } else { serverController.StartKyoku(); return new AfterStartKyokuState(this); } } } else { //errorhandling serverController.SendErrorToRoomMember(msgobj); } return this; }