Ejemplo n.º 1
0
 private static void LoadToonsForAccountID(Account a)
 {
     if (_characters == null) { _characters = new AccountDBDataSetTableAdapters.charactersTableAdapter(); }
     var data = _characters.GetToonsByOwnerID(a.Serial);
     foreach (var row in data)
         a.Toons.Add(ServerToon.LoadDataBlob(row));
 }
Ejemplo n.º 2
0
 private void handleClientAuthReq(NetworkStream client, LoginRequest loginRequest,Account p)
 {
     Logger.Log("User: "******" Connecting...");
     Database.LoadAccountInto(p,loginRequest.UserName, loginRequest.Password);
     //if (OnlineAccounts.Where(a => a.Serial == p.Serial).Count() > 1)
     //    OnlineAccounts.Remove(OnlineAccounts.Where(a => a.Serial == p.Serial).First());
     new LoginResponse(p.GetToonNames()).Send(client);
     Logger.Log("Sent Login Response");
     return;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when a player logs on and his toon joins a scene.
        /// </summary>
        /// <param name="player"></param>
        internal void ToonJoinWorld(Account player)
        {
            Logger.Log(player.CurrentToon.Name + " Joined Scene : " + Serial + " Sending reveal to " + Toons.Count + " clients");
            ShowOtherToon show = new ShowOtherToon(player.CurrentToon);
            foreach (var t in Toons) {
                show.Send(t); // Reveal new player to old players.
                new ShowOtherToon(t.CurrentToon).Send(player);//.Send(player.Client.GetStream());// Reveal current players to new player

            }
            Toons.Add(player);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Called when a player logs off or is dissconnected etc.
        /// </summary>
        /// <param name="player"></param>
        internal void ToonLeaveWorld(Account player)
        {
            if (!Toons.Contains(player))
                return;
            Logger.Log(player.CurrentToon.Name + " Left Scene : " + Serial + " Sending Remove to " + Toons.Count + " clients");
            //TODO send player gone packet.

            Toons.Remove(player);
            foreach (var t in Toons) {
                new DeleteObject(player.CurrentToon.Serial).Send(t.Client.GetStream());
            }
        }
Ejemplo n.º 5
0
        internal static Toon CreateToon(Account p, ProtoShared.Packets.FromClient.CreateCharacter createCharacter)
        {
            if (_characters == null) _characters = new AccountDBDataSetTableAdapters.charactersTableAdapter();
            Toon toon = new Toon();
            toon.SceneSerial = 1;
            toon.Name = createCharacter.Name;
            toon.Location = new Vector3D(905, 13, 593);
            toon.Attributes.Add(new Attrib() { ID = AttribType.Health, Value = 50 });
            toon.Attributes.Add(new Attrib() { ID = AttribType.MaxHealth, Value = 50 });
            _characters.Insert(p.Serial, toon.Name, toon.GetData());

            LoadToonsForAccountID(p);
            return p.Toons.Where(t => t.Name.Equals(createCharacter.Name)).First();
        }
Ejemplo n.º 6
0
        internal static void LoadAccountInto(Account a,string p1, string p2)
        {
            if (_accounts == null) _accounts = new AccountDBDataSetTableAdapters.accountsTableAdapter();
            var data = _accounts.GetAccountID(p1, p2);
            if (data.Rows.Count == 0) {
                Logger.Log("No User found in DB, Creating...");
                _accounts.Insert(p1, p2);

                LoadAccountInto(a, p1, p2);
                return;

            }
            Logger.Log("Found User..." + p1 + "  " + data[0].id);
            a.UserName = p1;
            a.Serial = data[0].id;
            LoadToonsForAccountID(a);
            return;
        }
Ejemplo n.º 7
0
        private bool HandleClientMessages(Account p,long delta)
        {
            if (p.Client == null || !p.Client.Connected)
                return false;
            p.TimeSincePingSent += delta;
            //Send ping every 30 seconds
            if (p.TimeSincePingSent > (30 * 1000)) {
                if (!new ProtoShared.Packets.Shared.Ping() { TimeStamp = System.DateTime.Now.ToFileTimeUtc() }.Send(p)) { return false; }
                p.TimeSincePingSent = 0;
                p.LastPing++;
            }

            //If last recieved ping back was more than 60 seconds, DC
            if (p.LastPing > 2) {
                Logger.Log("Dissconnecting client " + p.UserName + " due to no pings");
                return false;
            }

            while (p.Client.Available > 1) {
                var data = Serializer.DeserializeWithLengthPrefix<BaseMessage>(p.Client.GetStream(), PrefixStyle.Base128);
                //Logger.Log(data.GetType().ToString() + "    " + data.PacketType);
                        switch (data.PacketType) {
                            case OpCodes.C_LoginRequest:
                                handleClientAuthReq(p.Client.GetStream(), (LoginRequest)data,p);
                                break;
                            case OpCodes.S_Ping:
                                handlePing(p, (ProtoShared.Packets.Shared.Ping)data);
                                break;
                            case OpCodes.C_CreateCharacter:
                                handleCreateToon(p, (CreateCharacter)data);
                                break;
                            case OpCodes.C_SelectCharacter:
                                handleSelectToon(p.Client.GetStream(), (SelectCharacter)data, p);
                                break;
                            case OpCodes.C_DissconnectRequest:
                                return false;
                            default:
                                if (OnPacketarrival != null)
                                    OnPacketarrival(p, data);
                                break;

                        }

            }
            return true;
        }
Ejemplo n.º 8
0
 private void handleSelectToon(NetworkStream client, SelectCharacter selectCharacter, Account account)
 {
     int index = Math.Max(0,Math.Min(selectCharacter.ToonID, account.Toons.Count));
     account.CurrentToon = account.Toons[index];
     Logger.Log("Entering world..." + account.CurrentToon.Name);
     WorldManager.PlayerJoinScene(account);
     new EnterWorld((Toon)account.CurrentToon).Send(client);
     return;
 }
Ejemplo n.º 9
0
 private void handlePing(Account p, ProtoShared.Packets.Shared.Ping ping)
 {
     p.LastPing = 0;
 }
Ejemplo n.º 10
0
 private void handleCreateToon(Account p, CreateCharacter createCharacter)
 {
     p.CurrentToon = Database.CreateToon(p, createCharacter);
     WorldManager.PlayerJoinScene(p);
     new EnterWorld((Toon)p.CurrentToon).Send(p.Client.GetStream());
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Packet handler for Scene related Messages
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="msg"></param>
 void ClientManager_OnPacketarrival(Account owner, ProtoShared.Packets.BaseMessage msg)
 {
     switch (msg.PacketType) {
         case OpCodes.C_MoveRequest:
             handleMoveRequest(owner.CurrentToon, (MoveRequest)msg);
             break;
         case OpCodes.S_ChatMessage:
             handleChatMessage(owner, (ChatMessage)msg);
             break;
     }
 }
Ejemplo n.º 12
0
 private void handleChatMessage(Account a, ChatMessage chatMessage)
 {
     Logger.Log(chatMessage.Sender + ": " + chatMessage.Message);
     foreach (var p in Toons)
         if (a.Serial != p.Serial)
             chatMessage.Send(p.Client.GetStream());
 }
Ejemplo n.º 13
0
 internal static void PlayerLeaveScene(Account player)
 {
     if(player.CurrentToon.SceneSerial != 0)
     Scenes[player.CurrentToon.SceneSerial].ToonLeaveWorld(player);
 }
Ejemplo n.º 14
0
 internal static void PlayerJoinScene(Account player)
 {
     Scenes[player.CurrentToon.SceneSerial].ToonJoinWorld(player);//.Toons.Add(player);
 }