Example #1
0
        protected void HandleLogin(byte[] message)
        {
            try
            {
                if (isLoggedIn) return;
                byte version = message[0];
                USERNAME = enc.GetString(message, 1, 64).Trim();
                string verify = enc.GetString(message, 65, 32).Trim();
                byte type = message[129];
                if (!VerifyAccount(USERNAME, verify)) return;
                if (version != ServerSettings.version) { SKick("Wrong Version!."); return; }

                OnPlayerConnect e = new OnPlayerConnect(this);
                e.Call();

                //TODO Database Stuff

                Server.Log("[System]: " + ip + " logging in as " + USERNAME + ".", ConsoleColor.Green, ConsoleColor.Black);
                UniversalChat(USERNAME + " joined the game!");

                CheckDuplicatePlayers(USERNAME);

                SendMotd();

                isLoading = true;
                SendMap();
                if (!isOnline) return;
                isLoggedIn = true;

                id = FreeId();
                UpgradeConnectionToPlayer();

                //Do we want the same-ip-new-account code?

                //ushort x = (ushort)((0.5 + level.SpawnPos.x) * 32);
                //ushort y = (ushort)((1 + level.SpawnPos.y) * 32);
                //ushort z = (ushort)((0.5 + level.SpawnPos.z) * 32);

                short x = (short)((0.5 + level.SpawnPos.x) * 32);
                short y = (short)((1 + level.SpawnPos.y) * 32);
                short z = (short)((0.5 + level.SpawnPos.z) * 32);

                //x = (ushort)Math.Abs(x);
                //y = (ushort)Math.Abs(y);
                //z = (ushort)Math.Abs(z);

                Pos = new Point3(x, z, y);
                Rot = level.SpawnRot;
                oldPos = Pos;
                oldRot = Rot;

                SpawnThisPlayerToOtherPlayers();
                SpawnOtherPlayersForThisPlayer();
                SendSpawn(this);

                isLoading = false;

            }
            catch (Exception e)
            {
                Server.Log(e);
            }
        }
 /// <summary>
 /// Unregisters the specific event
 /// </summary>
 /// <param name="pe">The event to unregister</param>
 public static void Unregister(OnPlayerConnect pe)
 {
     pe.Unregister();
 }
 /// <summary>
 /// Used to register a method to be executed when the event is fired.
 /// </summary>
 /// <param name="callback">The method to call</param>
 /// <param name="target">The player to watch for. (null for any players)</param>
 /// <returns>the new OnPlayerConnect event</returns>
 public static OnPlayerConnect Register(OnCall callback, Player target)
 {
     Logger.Log("OnPlayerConnect registered to the method " + callback.Method.Name, LogType.Debug);
     //We add it to the list here
     OnPlayerConnect pe = _eventQueue.Find(match => (match.Player == null ? target == null : target != null && target.Username == match.Player.Username));
     if (pe != null)
         //It already exists, so we just add it to the queue.
         pe._queue += callback;
     else {
         //Doesn't exist yet.  Make a new one.
         pe = new OnPlayerConnect(callback, target);
         _eventQueue.Add(pe);
     }
     return pe;
 }
 void OnConnect(OnPlayerConnect args)
 {
     if (mPlayersListBox.InvokeRequired) {
         mPlayersListBox.Invoke((MethodInvoker)delegate { OnConnect(args); });
         return;
     }
     mPlayersListBox.Items.Add(args.Player.Username);
 }