Esempio n. 1
0
 public void ClearBoard(Mobile from, PlayerInfo player)
 {
     if (from != player.mobile)
     {
         from.SendMessage("This game needs maintenance.");
         SecurityCamera(0, "This game needs maintenance.");
         Active = false;
         return;
     }
     PayMethod PayTable = PayMethod.QuickPick;
     byte[] Selected = new byte[80];
     byte[] MachinePicks = new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
     byte TotalSelected = 15;
     byte[] TPicks = PickNumbers(TotalSelected);
     for (int i = 0; i < TotalSelected; i++)
         Selected[TPicks[i]] = 1;
     from.CloseGump(typeof(KenoGump));
     from.SendGump(new KenoGump(this, from, player, false, (int)PayTable, GetPayTable((int)PayTable, player.Cost, TotalSelected), 2, TotalSelected, false, Selected, TotalSelected, MachinePicks));
     player.LastPlayed = DateTime.Now;
 }
Esempio n. 2
0
        public void DoCashOut(Mobile from, PlayerInfo player)
        {

            if (from != player.mobile)
            {
                from.SendMessage("This game needs maintenance.");
                SecurityCamera(0, "This game needs maintenance.");
                Active = false;
                return;
            }
            int credit = player.OnCredit;
            if (from == null || credit == 0)
                return;
            if (!m_Active && (m_ErrorCode == 9500 || m_ErrorCode == 9501 || m_ErrorCode == 9502)) // Prevent a loop cashing out
                return;
            if (from != player.mobile)
            {
                from.SendMessage("You are no longer playing this game!");
                return;
            }
            if (player.OnCredit < 0) // This should never happen but protect against some kind of overflow and a wild payout
            {
                if (from.AccessLevel >= AccessLevel.GameMaster) // Allow a GM to clear out the invalid amount
                {
                    from.SendMessage("Invalid gold won amount({0}), reset to 0.", player.OnCredit);
                    player.OnCredit = 0;
                }
                from.SendMessage("There's a problem with this machine's gold amount, this game is offline. Page for help.");
                KenoOffline(9502);
                return;
            }
            if (player.OnCredit < 1000)
            {
                try
                {
                    from.AddToBackpack(new Gold(player.OnCredit));
                    from.SendMessage("{0} gold has been added to your pack.", credit);
                }
                catch
                {
                    from.SendMessage("There's a problem returning your gold, this game is offline. Page for help.");
                    KenoOffline(9500);
                    return;
                }
            }
            else
            {
                try
                {
                    from.AddToBackpack(new BankCheck(player.OnCredit));
                    from.SendMessage("A bank check for {0} gold has been placed in your pack.", credit);
                }
                catch
                {
                    from.SendMessage("There's a problem returning your gold, this game is offline. Page for help.");
                    KenoOffline(9501);
                    return;
                }

            }
            player.OnCredit = 0;
            string text = null;
            if (credit >= 10000)
            {
                text = String.Format("{0} is cashing out {1} Gold!", from.Name, credit);
                this.PublicOverheadMessage(0, (this.Hue == 907 ? 0 : this.Hue), false, text);
            }
            text = String.Format("{0} is cashing out {1} Gold!", from.Name, credit);
            SecurityCamera(credit >= 10000 ? 0 : 1, text);
            from.PlaySound(52);
            from.PlaySound(53);
            from.PlaySound(54);
            from.PlaySound(55);
        }
Esempio n. 3
0
 public int ProcessPlay(Mobile from, PlayerInfo player, int amount)
 {
     player.OnCredit += amount;
     if (player.Cost * 2 < amount && !m_Profile)
         DoWinSound(from, player.mobile.Female, amount);
     m_TotalWon += (ulong)amount;
     UpdateLastWonBy(from, amount);
     string text = null;
     if (amount > 499999 && !m_Profile)
     {
         if (m_MembershipCard)
             IssueMembershipCard(from, amount);
         if (m_AnnounceBigWins)
         {
             text = String.Format("{0} has won {1} gold on {2}!", from.Name, amount, this.Name);
             AnnounceWin(from, text);
         }
     }
     text = String.Format("{0} wins {1}.", from.Name, amount);
     SecurityCamera(amount > 5000 ? 0 : 1, text);
     text = String.Format("OnCredit={1}.", player.mobile.Name, player.OnCredit);
     SecurityCamera(player.OnCredit > 10000 ? 1 : 2, text);
     return player.OnCredit;
 }
Esempio n. 4
0
 public int OnCredit(Mobile from, PlayerInfo player, int amount)
 {
     if (from == null || player == null || from != player.mobile)
     {
         from.SendMessage("This game needs maintenance.");
         SecurityCamera(0, "This game needs maintenance.");
         Active = false;
         return player.OnCredit;
     }
     player.OnCredit += amount;
     if (amount < 0)
         m_TotalCollected += (ulong)Math.Abs(amount);
     return player.OnCredit;
 }
Esempio n. 5
0
 public bool RemovePlayer(Mobile from, PlayerInfo player)
 {
     if (from != player.mobile)
     {
         from.SendMessage("This game needs maintenance.");
         SecurityCamera(0, "This game needs maintenance.");
         Active = false;
         return false;
     }
     string text = String.Format("Removing: {0}.", player.mobile.Name);
     SecurityCamera(0, text);
     if (player.OnCredit != 0)
         DoCashOut(from, player);
     PlayerList.Remove(player);
     m_TotalPlayers--;
     InvalidateProperties();
     return true;
 }
Esempio n. 6
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
            m_Active = reader.ReadBool();
            m_Theme = (ThemeType)reader.ReadInt();
            m_TotalSpins = reader.ReadULong();
            m_TotalCollected = reader.ReadULong();
            m_TotalWon = reader.ReadULong();
            m_ErrorCode = reader.ReadInt();
            m_OrigHue = reader.ReadInt();
            m_Throttle = reader.ReadBool();
            m_ThrottleSeconds = reader.ReadDouble();
            m_CardClubOnly = reader.ReadBool();
            m_MembershipCard = reader.ReadBool();

            m_LastWonBy = reader.ReadMobile();
            m_LastWonByDate = reader.ReadDateTime();
            m_LastWonAmount = reader.ReadInt();

            m_SecurityCamMobile = reader.ReadMobile();
            m_SecurityChatter = (VerboseType)reader.ReadInt();
            m_TotalPlayers = reader.ReadInt();
            InvalidateProperties();
            if (m_TotalPlayers > 0)
            {
                for (int i = 0; i < m_TotalPlayers; i++)
                {
                    PlayerInfo player = new PlayerInfo();

                    player.mobile = reader.ReadMobile();
                    player.LastPlayed = reader.ReadDateTime();
                    player.OnCredit = reader.ReadInt();
                    player.Cost = reader.ReadInt();
                    PlayerList.Add(player);
                }
            }

            for (int i = 0; i < m_HitStats.Length; i++)
                m_HitStats[i] = reader.ReadULong();

            if (m_OrigHue != -1 && m_Active)
            {
                this.Hue = m_OrigHue;
                m_OrigHue = -1;
            }
            SetupTheme(m_Theme);
            ActivateIdleTimer(TimeSpan.FromMinutes(5));
            m_GameSpeed = Utility.RandomList(5, 6, 7, 8, 9, 10, 11, 12);
        }
Esempio n. 7
0
 public PlayerInfo AddNewPlayer(Mobile from)
 {
     if (PlayerList.Count > MAXUSERS)
     {
         from.SendMessage("This game is full, try again later.");
         return null;
     }
     for (int i = 0; i < PlayerList.Count; i++)
     {
         PlayerInfo p = (PlayerInfo)PlayerList[i];
         if (p.mobile == null)
         {
             p.mobile = from;
             p.LastPlayed = DateTime.Now;
             p.OnCredit = 0;
             p.Cost = 1;
             m_TotalPlayers++;
             InvalidateProperties();
             return p;
         }
     }
     PlayerInfo player = new PlayerInfo();
     player.mobile = from;
     player.LastPlayed = DateTime.Now;
     player.OnCredit = 0;
     InvalidateProperties();
     player.Cost = 1;
     PlayerList.Add(player);
     m_TotalPlayers++;
     InvalidateProperties();
     /*for (int i = 0; i < PlayerList.Count; i++)
     {
         PlayerInfo tplayer = (PlayerInfo) PlayerList[i];
         //Console.WriteLine("(AddNewPlayer) Added/{0}/{1}", i, tplayer.mobile);
     }*/
     return player;
 }
Esempio n. 8
0
 public bool SearchForPlayer(Mobile from, out PlayerInfo player)
 {
     for (int i = 0; i < PlayerList.Count; i++)
     {
         player = (PlayerInfo)PlayerList[i];
         if (player.mobile == from)
         {
             player.LastPlayed = DateTime.Now;
             return true;
         }
     }
     player = null;
     return false;
 }
Esempio n. 9
0
        public bool CashCheck(Mobile m, PlayerInfo player, out int amount)
        {
            amount = 0;
            if (m != player.mobile)
            {
                m.SendMessage("This game needs maintenance.");
                SecurityCamera(0, "This game needs maintenance.");
                Active = false;
                return false;
            }
            if (m == null || m.Backpack == null || player == null)
                return false;
#if RUNUO2RC1
			List<Item> packlist = m.Backpack.Items;
#else
			ArrayList packlist = m.Backpack.Items;
#endif

            for (int i = 0; i < packlist.Count; ++i)
            {
                Item item = (Item)packlist[i];
                if (item != null && !item.Deleted && item is BankCheck)
                {
                    amount = ((BankCheck)item).Worth;
                    item.Delete();
                    if (item.Deleted)
                    {
                        string text = null;
                        Effects.PlaySound(new Point3D(this.X, this.Y, this.Z), this.Map, 501);
                        player.OnCredit += amount;
                        text = String.Format("{0}:Check={1}.", player.mobile.Name, amount);
                        SecurityCamera(amount > 5000 ? 0 : 1, text);
                        text = String.Format("OnCredit={1}.", player.mobile.Name, player.OnCredit);
                        SecurityCamera(player.OnCredit > 10000 ? 1 : 2, text);
                    }
                    else
                    {
                        m.SendMessage("There's a problem trying to cash a check in your backpack, this game is offline. Page for help.");
                        KenoOffline(9503);
                        return false;
                    }
                    return true;
                }
            }
            return false;
        }
Esempio n. 10
0
        static void ReceiveClientProcess(Object socket)
        {
            bool bQuit = false;

            // Cast object argument back into a socket
            Socket chatClient = (Socket)socket;

            // Server console debug message
            Console.WriteLine("client receive thread for " + GetNameFromSocket(chatClient));

            // Create a new Player class instance
            Player newPlayer = new Player(GetNameFromSocket(chatClient));

            // Initialise the start location
            newPlayer.CurrentRoom = myDungeon.StartRoom;

            // Locking on heavens door
            lock (playerDictionary)
            {
                // Sanity check, then add new Player and appropriate socket as a PlayerInfo struct to the playerDictionary with the clientName as the dictionary's key
                if (playerDictionary.ContainsKey(GetNameFromSocket(chatClient)))
                {
                    playerDictionary[GetNameFromSocket(chatClient)] = new PlayerInfo(newPlayer, chatClient);
                }
                else
                {
                    playerDictionary.Add(GetNameFromSocket(chatClient), new PlayerInfo(newPlayer, chatClient));
                }
            }

            // On new player instantiation, update all players with the new client list
            SendClientList();

            // Initialise string that will recieve the message from the server
            String sendMsg = "";

            while (bQuit == false)
            {
                try
                {
                    byte[] buffer = new byte[4096];
                    int    result;

                    result = chatClient.Receive(buffer);

                    if (result > 0)
                    {
                        MemoryStream stream = new MemoryStream(buffer);
                        BinaryReader read   = new BinaryReader(stream);

                        Msg message = Msg.DecodeStream(read);

                        if (message != null)
                        {
                            Console.Write("Got a message: ");
                            switch (message.mID)
                            {
                            case PublicChatMsg.ID:
                            {
                                PublicChatMsg publicMsg = (PublicChatMsg)message;

                                String formattedMsg = "<" + GetNameFromSocket(chatClient) + "> " + publicMsg.msg;

                                Console.WriteLine("public chat - " + formattedMsg);

                                SendChatMessage(formattedMsg);
                            }
                            break;

                            case PrivateChatMsg.ID:
                            {
                                PrivateChatMsg privateMsg = (PrivateChatMsg)message;

                                String formattedMsg = "PRIVATE <" + GetNameFromSocket(chatClient) + "> " + privateMsg.msg;

                                Console.WriteLine("private chat - " + formattedMsg + "to " + privateMsg.destination);

                                SendPrivateMessage(GetSocketFromName(privateMsg.destination), GetNameFromSocket(chatClient), formattedMsg);

                                formattedMsg = "<" + GetNameFromSocket(chatClient) + "> --> <" + privateMsg.destination + "> " + privateMsg.msg;
                                SendPrivateMessage(chatClient, "", formattedMsg);
                            }
                            break;

                            case GameMsg.ID:
                            {
                                // Cast back to GameMsg class
                                GameMsg gameMessage = (GameMsg)message;

                                // Get the string from the GameMsg class
                                String formattedMsg = gameMessage.msg;

                                // Filter the incoming message for a reference to another player and store
                                // Empty player with otherwise unassignable name, this can be picked up in the controls checks
                                Player   targetedOtherPlayer  = null;     // new Player("unassigned", new List<Item>());
                                String[] FormattedStringWords = formattedMsg.Split(' ');
                                foreach (String possibleName in FormattedStringWords)
                                {
                                    if (playerDictionary.ContainsKey(possibleName))
                                    {
                                        targetedOtherPlayer = playerDictionary[possibleName].player;
                                        break;
                                    }
                                }

                                // Get the sending client name, to be used as a dictionary key next, and to pass the String value
                                String clientName = GetNameFromSocket(chatClient);

                                // Lock it before changing it
                                lock (playerDictionary)
                                {
                                    // Temporary variable to alter outside of dictionary
                                    Player tempPlayer = playerDictionary[clientName].player;

                                    // Update function of the DungeonClass instance. If moved, Updates the current room of the player instance, and the currentRoom occupency of the dungeon room
                                    sendMsg = controls.Update(ref tempPlayer, ref targetedOtherPlayer, formattedMsg);

                                    // Console debug message
                                    Console.WriteLine(sendMsg);

                                    // Update dictionary variable
                                    playerDictionary[clientName] = new PlayerInfo(tempPlayer, playerDictionary[clientName].socket);

                                    // Parse the returned String from the controls for any server specific commands. Program.cs is the glue which holds the playerDictionary together.
                                    // OUTBOUND STRING PARSING!!! Is this a good idea?

                                    // Try/catch is needed to avoid crashing due to mismatched string sizes. i.e. comparing the first 14 characters of a 10 length string.

                                    // "Say" command will always return a sendMsg beginning with "Room chat:". If true then send private message to all players in room
                                    try
                                    {
                                        if (sendMsg.Substring(0, 10) == "Room chat:")
                                        {
                                            foreach (String playerName in tempPlayer.GetCurrentRoomRef.PlayersInRoom)
                                            {
                                                SendPrivateMessage(playerDictionary[playerName].socket, "", sendMsg);
                                            }
                                            break;
                                        }
                                    }
                                    catch
                                    {
                                    }



                                    // If sendMsg conditions have not returned true for any of the ablove specific cases, then send the message to the player socket
                                    SendGameMessage(chatClient, "", sendMsg);
                                }
                            }
                            break;

                            case PlayerInitMsg.ID:
                            {
                                // Cast back to GameMsg class
                                PlayerInitMsg playerInitMessage = (PlayerInitMsg)message;

                                // Get the string from the PlayerInitMsg class
                                // String characterSheetString = playerInitMessage.msg;

                                // String[] processedCharacterSheet = characterSheetString.Split(' ');

                                // Get the sending client name, to be used as a dictionary key next, and to pass the String value
                                String clientName = GetNameFromSocket(chatClient);

                                // Lock
                                lock (playerDictionary)
                                {
                                    // Temporary variable to assign value outside of dictionary
                                    Player tempPlayer = playerDictionary[clientName].player;


                                    // Update dictionary variable
                                    playerDictionary[clientName] = new PlayerInfo(tempPlayer, playerDictionary[clientName].socket);
                                }
                            }
                            break;

                            default:
                                break;
                            }
                        }
                    }
                }

                // Remove player from game
                catch (Exception)
                {
                    bQuit = true;

                    // Lost the player message
                    String output = "Lost client: " + GetNameFromSocket(chatClient);

                    // Debug message to server console
                    Console.WriteLine(output);

                    // Inform the other players
                    SendChatMessage(output);

                    // Always lock the list!!!
                    lock (playerDictionary)
                    {
                        try
                        {
                            // Sanity check, then remove player name from the current rooms list of currently occupying players names
                            if (playerDictionary[GetNameFromSocket(chatClient)].player.GetCurrentRoomRef.PlayersInRoom.Contains(GetNameFromSocket(chatClient)))
                            {
                                playerDictionary[GetNameFromSocket(chatClient)].player.GetCurrentRoomRef.RemovePlayer(GetNameFromSocket(chatClient));
                            }

                            // Sanity check, then remove player information from playerDictionary
                            if (playerDictionary.ContainsKey(GetNameFromSocket(chatClient)))
                            {
                                playerDictionary.Remove(GetNameFromSocket(chatClient));
                            }
                        }
                        catch (Exception)
                        { }
                    }

                    // Update all other players current client list
                    SendClientList();
                }
            }
        }
        public void StartServer()
        {
            TcpListener tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 7777);

            tcpListener.Start();
            Console.WriteLine("Server started");
            Random rnd = new Random();

            while (true)
            {
                if (tcpListener.Pending())
                {
                    Console.WriteLine("New pending connection");
                    tcpListener.BeginAcceptTcpClient(AcceptTcpClient, tcpListener);
                }

                foreach (Player player in _playerList)
                {
                    switch (player.GameState)
                    {
                    case GameState.Connecting:
                        if (player.DataAvailable())
                        {
                            Console.WriteLine("New player registering");
                            string playerJson = player.BinaryReader.ReadString();
                            Player playerMsg  = JsonConvert.DeserializeObject <Player>(playerJson);
                            player.Name = playerMsg.Name;

                            foreach (Player notifyPlayer in _playerList)
                            {
                                Message msg = new Message();
                                msg.MessageType = MessageType.NewPlayer;
                                msg.Description = (notifyPlayer == player) ?
                                                  "Successfully joined" :
                                                  "Player " + player.Name + " has joined";
                                PlayerInfo playerInfo = new PlayerInfo();
                                playerInfo.Id       = player.Id;
                                playerInfo.Name     = player.Name;
                                playerInfo.X        = 0;
                                playerInfo.Y        = 0;
                                playerInfo.Z        = 0;
                                playerInfo.Rotation = 0;
                                playerInfo.HP       = 3;
                                msg.PlayerInfo      = playerInfo;

                                int slot = Array.IndexOf(picked, false);
                                playerInfo.SpawnLocation = slot;
                                picked[slot]             = true;
                                Console.WriteLine(slot);

                                string msgJson = JsonConvert.SerializeObject(msg);
                                notifyPlayer.BinaryWriter.Write(msgJson);
                                notifyPlayer.MessageList.Add(msg);
                                Console.WriteLine(msgJson);
                            }
                            player.GameState = GameState.Sync;
                        }
                        break;

                    case GameState.Sync:
                        Console.WriteLine("New player sync");
                        // processar todos os NewPlayer
                        SyncNewPlayers(player);
                        Console.WriteLine("1231231212");
                        // processar todos os PlayerMovement
                        SyncPlayerMovement(player);

                        Message messagePlayer = new Message();
                        messagePlayer.MessageType = MessageType.FinishedSync;
                        string msgPlayerJson = JsonConvert.SerializeObject(messagePlayer);
                        player.BinaryWriter.Write(msgPlayerJson);
                        player.GameState = GameState.GameStarted;
                        Console.WriteLine(msgPlayerJson);
                        Console.WriteLine("dg4gaegae");
                        break;

                    case GameState.GameStarted:
                        if (player.DataAvailable())
                        {
                            Console.WriteLine("New player position");
                            string msgJson = player.BinaryReader.ReadString();
                            Console.WriteLine(msgJson);
                            Message message = JsonConvert.DeserializeObject <Message>(msgJson);
                            if (message.MessageType == MessageType.PlayerMovement)
                            {
                                //if(message.PlayerInfo.HP <= 0)
                                //{
                                //   var remove = _playerList.First(item => item.Name == player.Name);
                                //    _deadPlayerList.Add(remove);
                                //    _playerList.Remove(remove);
                                //}
                                foreach (Player p in _playerList)
                                {
                                    if (p.GameState == GameState.GameStarted)
                                    {
                                        p.BinaryWriter.Write(msgJson);
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }