private static void SendState(ReadyStatus status) { IWriteMessage msg = new WriteOnlyMessage(); msg.Write((byte)ClientPacketHeader.READY_CHECK); msg.Write((byte)ReadyCheckState.Update); msg.Write((byte)status); GameMain.Client?.ClientPeer?.Send(msg, DeliveryMethod.Reliable); }
private void UpdateState(byte id, ReadyStatus status) { if (Clients.ContainsKey(id)) { Clients[id] = status; } if (resultsBox == null || resultsBox.Closed || !GUIMessageBox.MessageBoxes.Contains(resultsBox)) { return; } if (resultsBox.Content.FindChild(UserListData) is GUIListBox userList) { // for some reason FindChild doesn't work here? foreach (GUIComponent child in userList.Content.Children) { if (!(child.UserData is byte b) || b != id) { continue; } if (child.GetChild <GUILayoutGroup>().FindChild(ReadySpriteData) is GUIImage image) { string style; switch (status) { case ReadyStatus.Yes: style = "MissionCompletedIcon"; break; case ReadyStatus.No: style = "MissionFailedIcon"; break; default: return; } image.ApplyStyle(GUI.Style.GetComponentStyle(style)); } } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ReadyStatus v = (ReadyStatus)value; switch (v) { case ReadyStatus.NotReady: return(.9); case ReadyStatus.Ready: return(.9); case ReadyStatus.Undefined: return(.9); default: return(0); } }
private void UpdateReadyCheck(byte otherClient, ReadyStatus state) { if (Clients.All(pair => pair.Value != ReadyStatus.Unanswered)) { EndReadyCheck(); return; } foreach (Client client in ActivePlayers) { IWriteMessage msg = new WriteOnlyMessage(); msg.Write((byte)ServerPacketHeader.READY_CHECK); msg.Write((byte)ReadyCheckState.Update); msg.Write(time); // sync time msg.Write((byte)state); msg.Write(otherClient); GameMain.Server.ServerPeer.Send(msg, client.Connection, DeliveryMethod.Reliable); } }
public static void ServerRead(IReadMessage inc, Client client) { ReadyCheckState state = (ReadyCheckState)inc.ReadByte(); ReadyCheck? readyCheck = GameMain.GameSession?.CrewManager?.ActiveReadyCheck; switch (state) { case ReadyCheckState.Start when readyCheck == null: StartReadyCheck(client.Name, client); break; case ReadyCheckState.Update when readyCheck != null: ReadyStatus status = (ReadyStatus)inc.ReadByte(); if (!readyCheck.Clients.ContainsKey(client.ID)) { return; } readyCheck.Clients[client.ID] = status; readyCheck.UpdateReadyCheck(client.ID, status); break; } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ReadyStatus v = (ReadyStatus)value; string img = "resources/images/Icon_Laurels/blank.png"; switch (v) { case ReadyStatus.NotReady: img = "resources/images/ic_close_white_24dp_2x.png"; break; case ReadyStatus.Ready: img = "resources/images/ic_done_white_24dp_2x.png"; break; case ReadyStatus.Undefined: img = "resources/images/ic_remove_white_24dp_2x.png"; break; default: break; } return(img); }
public static void ClientRead(IReadMessage inc) { ReadyCheckState state = (ReadyCheckState)inc.ReadByte(); CrewManager? crewManager = GameMain.GameSession?.CrewManager; List <Client> otherClients = GameMain.Client.ConnectedClients; if (crewManager == null || otherClients == null) { if (state == ReadyCheckState.Start) { SendState(ReadyStatus.No); } return; } switch (state) { case ReadyCheckState.Start: bool isOwn = false; byte authorId = 0; float duration = inc.ReadSingle(); string author = inc.ReadString(); bool hasAuthor = inc.ReadBoolean(); if (hasAuthor) { authorId = inc.ReadByte(); isOwn = authorId == GameMain.Client.ID; } ushort clientCount = inc.ReadUInt16(); List <byte> clients = new List <byte>(); for (int i = 0; i < clientCount; i++) { clients.Add(inc.ReadByte()); } ReadyCheck rCheck = new ReadyCheck(clients, duration); crewManager.ActiveReadyCheck = rCheck; if (isOwn) { SendState(ReadyStatus.Yes); rCheck.CreateResultsMessage(); } else { rCheck.CreateMessageBox(author); } if (hasAuthor && rCheck.Clients.ContainsKey(authorId)) { rCheck.Clients[authorId] = ReadyStatus.Yes; } break; case ReadyCheckState.Update: float time = inc.ReadSingle(); ReadyStatus newState = (ReadyStatus)inc.ReadByte(); byte targetId = inc.ReadByte(); if (crewManager.ActiveReadyCheck != null) { crewManager.ActiveReadyCheck.time = time; crewManager.ActiveReadyCheck?.UpdateState(targetId, newState); } break; case ReadyCheckState.End: ushort count = inc.ReadUInt16(); for (int i = 0; i < count; i++) { byte id = inc.ReadByte(); ReadyStatus status = (ReadyStatus)inc.ReadByte(); crewManager.ActiveReadyCheck?.UpdateState(id, status); } crewManager.ActiveReadyCheck?.EndReadyCheck(); crewManager.ActiveReadyCheck?.msgBox?.Close(); crewManager.ActiveReadyCheck = null; break; } }
private void _processClientTransactions(object tcpClient) { try { _updateStatusBox("You've connected to the Server !!!\n"); TcpClient client = (TcpClient)tcpClient; myStream = client.GetStream(); int round = 1; done = false; while (!done) { if (myStream.DataAvailable) { object obj = bfmt.Deserialize(myStream); if (obj is PlayingCard) { _setMoneyPictureBoxVisible(_poolMoneyPictureBox, true); PlayingCard card = obj as PlayingCard; if (roundCount % 2 == 0) { _enableButton(_foldButton, true); _enableButton(_bidButton, true); myPlayer.MyHand[0] = card; _player1PictureBox1.Image = imageList.Images[card.ID]; } else { myPlayer.MyHand[1] = card; _player1PictureBox2.Image = imageList.Images[card.ID]; _updateStatusBox($"Round: {round}: {myPlayer.MyHand[0].Rank}, {myPlayer.MyHand[1].Rank}\n"); _updateBalance(initialBid, true); bfmt.Serialize(myStream, initialBid); round++; } roundCount++; // biddingPool = 0; _updatePoolMoneyLabel(50); //round 0 } else if (obj is PlayingCard[]) { opponentHands = obj as PlayingCard[]; if (myPlayer.MyHand.Length > 0) { for (int i = 0; i < opponentHands.Length; i++) { opBoxes[i].Image = imageList.Images[opponentHands[i].ID]; } } _checkWinCondition(); runTimer(); myPlayer.MyStatus = Status.Unassigned; } else if (obj is ReadyStatus) { ReadyStatus rs = (ReadyStatus)obj; if (rs == ReadyStatus.Ready) { bfmt.Serialize(myStream, myPlayer.MyHand); } } else if (obj is GameMessage) { GameMessage gm = obj as GameMessage; _updateStatusBox(gm.Message); } else if (obj is Status) { Status status = (Status)obj; if (status == Status.Fold) { opponentPoints = -1; bfmt.Serialize(myStream, Status.Bid); } if (status == Status.Bid) { _setMoneyPictureBoxVisible(_player2MoneyPictureBox, true); } } else if (obj is int) { biddingPool = (int)obj; _updatePoolMoneyLabel(biddingPool); } else if (obj is StartNewRound) { bfmt.Serialize(myStream, new StartNewRound()); _updatePoolMoneyLabel(biddingPool); } else if (obj is QuitGame) { _disconnectFromServer(); } } } _client.Close(); _updateStatusBox($"You've disconnected from the server !!!\n"); } catch (Exception ex) { _updateStatusBox($"problem communicating with the server. Connection may have been intentionally disconnected.\n"); _client.Close(); _updateStatusBox($"{ex.ToString()}\n");//this is good for an error log for showing to the user is not necessary } // _connectButton.Enabled = true; _enableButton(_connectButton, true); // _disconnectButton.Enabled = false; _enableButton(_disconnectButton, false); // _sendMessageButton.Enabled = false; _enableButton(_sendMessageButton, false); _enableButton(_setNameButton, false); }//End processClientTransactions
/// <summary> /// Updates the player's ready status. /// </summary> /// <param name="player">The player.</param> /// <param name="status">The status.</param> private void UpdatePlayerReadyStatus(string player, ReadyStatus status) { _sst.ServerInfo.CurrentPlayers[player].Ready = status; Log.Write(string.Format("{0}'s player status: {1}", player, status), _logClassType, _logPrefix); }
// TODO: Replace wavePrebbing and waveStarted with enums public IEnumerator PoolBaddies() { yield return(new WaitForSeconds(1f)); if (availableSpawns.Count == 0) { CancelWave(); readyStatus = ReadyStatus.EnemiesBuild; Game.ShowErrorMessage("Unable to start wave: Paths unclear", 3f); } else { Wave cur = waves[waveNumber - 1]; Queue <Wave.Enemy> spawnQueue = new Queue <Wave.Enemy>(); currentEnemies = 0; int index = -1; foreach (Wave.Subwave sub in cur.subwaves) { foreach (Wave.Enemy ene in sub.enemies) { index++; ene.index = index; spawnQueue.Enqueue(ene); SplitterEnemySplit split = ene.enemy.GetComponent <SplitterEnemySplit>(); if (split) { currentEnemies += Mathf.RoundToInt(ene.spawnAmount * (float)split.spawnPos.Length * amountModifier); } currentEnemies += Mathf.RoundToInt(ene.spawnAmount * amountModifier); } } int spawnPerTick = 256; List <Enemy> toArray = new List <Enemy>(); index = 0; while (spawnQueue.Count > 0) { for (int i = 0; i < Mathf.RoundToInt(spawnQueue.Peek().spawnAmount *amountModifier); i++) { GameObject newEne = (GameObject)Instantiate(spawnQueue.Peek().enemy, Vector3.right * 5000f, Quaternion.identity); toArray.Add(newEne.GetComponent <Enemy>()); newEne.SetActive(false); //newEne.transform.parent = enemyPool; Enemy e = newEne.GetComponent <Enemy>(); e.upcomingElement = upcomingElements[spawnQueue.Peek().index]; e.Initialize(); if (!pooledEnemies.ContainsKey(spawnQueue.Peek())) { pooledEnemies.Add(spawnQueue.Peek(), new List <GameObject>()); } pooledEnemies[spawnQueue.Peek()].Add(newEne); index++; if (index >= spawnPerTick) { yield return(new WaitForFixedUpdate()); index = 0; } } spawnQueue.Dequeue(); } spawnedEnemies = toArray; chanceToSpawnResearch = currentEnemies; readyStatus = ReadyStatus.EnemiesBuild; yield return(null); } }