Exemple #1
0
        public static void WritePlayerContactData(string name, PlayerContactData data)
        {
            // write json to simple text file
            var path = Path.Combine(CONTACTS_FOLDER, name);
            var ser  = API.shared.toJson(data);

            File.WriteAllText(path, ser);
            return;
        }
Exemple #2
0
        public static PlayerContactData ReadPlayerContactData(string name)
        {
            // read from simple file in path and load as json
            var path = Path.Combine(CONTACTS_FOLDER, name);
            var txt  = File.ReadAllText(path);
            PlayerContactData playerContacts = API.shared.fromJson(txt).ToObject <PlayerContactData>();

            return(playerContacts);
        }
Exemple #3
0
        public static void CreatePlayerContactsList(string name)
        {
            // initialize player contact data
            var PlayerContactData = new PlayerContactData()
            {
                socialClubName = name,
                contacts       = new List <ContactData>(),
            };

            WritePlayerContactData(name, PlayerContactData);
            return;
        }
Exemple #4
0
        public static string[] RemoveContactFromPlayerContactsList(string name, string removeName)
        {
            PlayerContactData PlayerContactData = GetPlayerContactData(name);

            // validate the name of the contact exists
            var contacts = PlayerContactData.contacts.Where(c => c.name == removeName);

            if (!contacts.Any())
            {
                string[] resultError = new string[] { "error", removeName };
                return(resultError);
            }

            // remove contact from players contacts list and save
            PlayerContactData.contacts.Remove(contacts.FirstOrDefault());
            WritePlayerContactData(name, PlayerContactData);

            string[] result = new string[] { "success", removeName };
            return(result);
        }
Exemple #5
0
        public static bool DoesPlayerExist(Client player, string name)
        {
            PlayerList playerList = ReadPlayerList();

            if (!playerList.players.Where(p => p.socialClubName == player.socialClubName).Any())
            {
                // create new phone number
                bool   numberAvailable = false;
                int    number          = 0;
                Random r = new Random();

                while (!numberAvailable)
                {
                    number  = r.Next(12000, 19999);
                    number += 42000000; // add number prefix
                    if (!playerList.players.Where(p => p.number == number.ToString()).Any())
                    {
                        numberAvailable = true;
                    }
                }

                PlayerContactData newPlayer = new PlayerContactData {
                    name           = name,
                    socialClubName = player.socialClubName,
                    number         = number.ToString(),
                    credits        = 0,
                    contacts       = new List <ContactData>(),
                };

                playerList.players.Add(newPlayer);
                WritePlayers(playerList);

                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #6
0
        public static PlayerContactData GetPlayerContactData(string name)
        {
            PlayerContactData PlayerContactData = ReadPlayerContactData(name);

            return(PlayerContactData);
        }
        //
        // triggered client events
        //

        public void OnClientEvent(Client player, string eventName, params object[] arguments)
        {
            // CONTACT_INFO
            if (eventName == "CONTACT_INFO_REQUEST")
            {
                // trigger client event and send data
                PlayerContactData contactData = Database.GetPlayerContactData(player.socialClubName);
                API.triggerClientEvent(player, "CONTACT_INFO_RESPONSE", contactData.credits);
                return;
            }

            // contact list request
            else if (eventName == "CONTACT_LIST_REQUEST")
            {
                // load contact from local database
                PlayerContactData contactData = Database.GetPlayerContactData(player.socialClubName);
                // send contact list as json to client
                API.triggerClientEvent(player, "CONTACT_LIST_RESPONSE", API.shared.toJson(contactData.contacts));
                return;
            }

            // add contact request
            else if (eventName == "ADD_CONTACT_REQUEST")
            {
                // adding number handeled separetly, the lgic will be used on edit cantact request
                AddNumber(player, arguments);
                return;
            }

            // recieve edit contact request
            else if (eventName == "EDIT_CONTACT_REQUEST")
            {
                // load contact from local database
                var contactData = Database.GetPlayerContactData(player.socialClubName);

                // check for existing number
                var existingNumberEntry = contactData.contacts.Where(c => c.number == arguments[2].ToString());

                if (!existingNumberEntry.Any())
                {
                    API.shared.consoleOutput("Existing number entry not found: " + arguments[2]);
                    API.triggerClientEvent(player, "EDIT_CONTACT_RESPONE_ERROR", "number_does_not_exist", arguments[2]);
                    return;
                }

                var existingEntry = existingNumberEntry.FirstOrDefault();
                API.shared.consoleOutput("Existing number entry name: " + existingEntry.name);
                API.shared.consoleOutput("Existing number entry number: " + existingEntry.number);

                // delete existing entry
                var resultDelete = Database.RemoveContactFromPlayerContactsList(player.socialClubName, existingEntry.name);
                if (resultDelete[0] != "success")
                {
                    //API.shared.consoleOutput("4444");
                    API.triggerClientEvent(player, "DELETE_CONTACT_RESPONSE_ERROR", resultDelete[0], existingEntry.name);
                    return;
                }

                // add number and send repsonse
                AddNumber(player, arguments);
                return;
            }

            // recieve delete contact request
            else if (eventName == "DELETE_CONTACT_REQUEST")
            {
                var name   = arguments[0].ToString();
                var result = Database.RemoveContactFromPlayerContactsList(player.socialClubName, name);
                if (result[0] != "success")
                {
                    API.triggerClientEvent(player, "DELETE_CONTACT_RESPONSE_ERROR", result[0], name);
                }
                API.triggerClientEvent(player, "DELETE_CONTACT_RESPONSE", result[0], name);
                return;
            }

            // CONTACT_CALL_REQUEST
            else if (eventName == "CONTACT_CALL_REQUEST")
            {
                // handle call request
                HandleCallRequest(player, arguments[0].ToString());
                return;
            }

            // CONTACT_CALL_REQUEST_CONFIRM
            else if (eventName == "CONTACT_CALL_REQUEST_CONFIRM")
            {
                // trigger client event and send data
                API.shared.consoleOutput("Player " + player.socialClubName + " confirmed incoming call.");
                return;
            }

            // CONTACT_CALL_REQUEST_CONFIRM_DECLINE
            else if (eventName == "CONTACT_CALL_REQUEST_CONFIRM_DECLINE")
            {
                // trigger client event and send data
                API.shared.consoleOutput("Player " + player.socialClubName + " denied incoming call.");
                return;
            }

            API.shared.consoleOutput("Something not implemented correctly " + eventName);
            return;
        }