public void ClientBuyStocks(Version serverversion, ICommunicateable communicator, MarketState marketstate, int stockstobuy) { try { if (serverversion.Major > 0) { Stock.Available = communicator.ReceiveInt(); if (stockstobuy > Stock.Available) { stockstobuy = Stock.Available; } communicator.SendInt(stockstobuy); communicator.SendDouble(Stock.Price); communicator.SendDouble(Stock.CalculatePrice(stockstobuy) + Stock.CalculateBrokerage(marketstate, stockstobuy)); Count = communicator.ReceiveInt(); Stock.Available = communicator.ReceiveInt(); Stock.OwnedByPlayers = communicator.ReceiveInt(); LastBuyPrice = communicator.ReceiveDouble(); Deposit.Player.Capital = communicator.ReceiveDouble(); } } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { if (full) { Id = communicator.ReceiveString(); Name = communicator.ReceiveString(); int c = communicator.ReceiveInt(); if (c > 0) { StockIndexes stockindexes = (StockIndexes) obj; for (int i = 0; i < c; i++) { string id = communicator.ReceiveString(); StockIndex stockindex = null; if (stockindexes.TryGetValue(id, out stockindex)) { stockindex.Stocks.Add(Id, this); StockIndexes.Add(stockindex.Id, stockindex); } } } PriceHistory.ClientCommunication(serverversion, communicator, full, obj); } if (serverversion.Major > 0 && serverversion.Minor >= 1) { MinPrice = communicator.ReceiveDouble(); MaxPrice = communicator.ReceiveDouble(); } else { MinPrice = MIN_PRICE; MaxPrice = MAX_PRICE; } Price = communicator.ReceiveDouble(); if (full && PriceHistory.Count > 0) PriceHistory.RemoveAt(PriceHistory.Count - 1); Available = communicator.ReceiveInt(); OwnedByPlayers = communicator.ReceiveInt(); } return this; } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { int c = communicator.ReceiveInt(); if (c > 0) { Enumerator e = this.GetEnumerator(); for (int i = 0; i < c; i++) { if (full) { Stock stock = new Stock(serverversion, communicator, full, obj); this.Add(stock.Id, stock); } else if (e.MoveNext()) { e.Current.Value.ClientCommunication(serverversion, communicator, full, obj); } } } } return(this); } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { while (this.Count > 0) { this.Clear(); } int c = communicator.ReceiveInt(); if (c > 0) { for (int i = 0; i < c; i++) { this.Add(communicator.ReceiveDouble()); } } } return(this); } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { int c = communicator.ReceiveInt(); if (c > 0) { System.Collections.Generic.Dictionary <string, DepositContent> .ValueCollection.Enumerator e = this.Values.GetEnumerator(); for (int i = 0; i < c; i++) { if (e.MoveNext()) { e.Current.ClientCommunication(serverversion, communicator, full, obj); } } } } return(this); } catch (System.Exception ex) { throw ex; } }
public void ServerBuyStocks(Version clientversion, ICommunicateable communicator) { try { if (clientversion.Major > 0) { communicator.SendInt(Stock.Available); int stockstobuy = communicator.ReceiveInt(); double stockprice = communicator.ReceiveDouble(); double price = communicator.ReceiveDouble(); if (stockstobuy > 0 && stockstobuy <= Stock.Available && Deposit.Player.Capital >= price) { Count += stockstobuy; Stock.Available -= stockstobuy; Stock.OwnedByPlayers += stockstobuy; LastBuyPrice = stockprice; Deposit.Player.Capital -= price; } communicator.SendInt(Count); communicator.SendInt(Stock.Available); communicator.SendInt(Stock.OwnedByPlayers); communicator.SendDouble(LastBuyPrice); communicator.SendDouble(Deposit.Player.Capital); } } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { State = (MarketStateType)communicator.ReceiveInt(); Epochs = communicator.ReceiveInt(); Brokerage = communicator.ReceiveDouble(); } return(this); } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { Count = communicator.ReceiveInt(); LastBuyPrice = communicator.ReceiveDouble(); LastSellPrice = communicator.ReceiveDouble(); } return(this); } catch (System.Exception ex) { throw ex; } }
public void ServerSellStocks(Version clientversion, ICommunicateable communicator) { try { if (clientversion.Major > 0) { int stockstosell = communicator.ReceiveInt(); double stockprice = communicator.ReceiveDouble(); double price = communicator.ReceiveDouble(); double brokerage = communicator.ReceiveDouble(); if (stockstosell > 0 && stockstosell < Count && price >= brokerage) { Count -= stockstosell; Stock.OwnedByPlayers -= stockstosell; Stock.Available += stockstosell; if (Count <= 0) { LastBuyPrice = 0; LastSellPrice = 0; } else { LastSellPrice = stockprice; } Deposit.Player.Capital += price - brokerage; } communicator.SendInt(Count); communicator.SendInt(Stock.OwnedByPlayers); communicator.SendInt(Stock.Available); communicator.SendDouble(LastBuyPrice); communicator.SendDouble(LastSellPrice); communicator.SendDouble(Deposit.Player.Capital); } } catch (System.Exception ex) { throw ex; } }
public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj) { try { if (serverversion.Major > 0) { while (NewPlayers.Count > 0) { NewPlayers.Clear(); } while (DisconnectedPlayers.Count > 0) { DisconnectedPlayers.Clear(); } DisconnectedPlayers.AddRange(this); int c = communicator.ReceiveInt(); if (c > 0) { for (int i = 0; i < c; i++) { int playerid = communicator.ReceiveInt(); bool containplayer = Contains(playerid); communicator.SendBool(containplayer); if (!containplayer) { Player player = new Player(playerid, serverversion, communicator, true, obj); this.Add(player); NewPlayers.Add(player); } else { Player player = GetPlayer(playerid); player.ClientCommunication(serverversion, communicator, false, obj); while (DisconnectedPlayers.Contains(player)) { DisconnectedPlayers.Remove(player); } } } } if (DisconnectedPlayers.Count > 0) { foreach (Player p in DisconnectedPlayers) { while (this.Contains(p)) { this.Remove(p); } } } } foreach (Player player in this) { if (player.IsYou) { return(player); } } return(null); } catch (System.Exception ex) { throw ex; } }