Esempio n. 1
0
        public static void AckLogin(byte[] buff)
        {
            LoginAck ack = ProtocolBuffConvert.Deserialize <LoginAck>(buff);

            OnLoginAck?.Invoke();
        }
Esempio n. 2
0
        private bool MessageReceived(byte[] data)
        {
            if (data == null || data.Length <= 0)
            {
                return(false);
            }

            try
            {
                using (var stream = new MemoryStream(data))
                {
                    var bProtocolVersion = new byte[4];
                    stream.Read(bProtocolVersion, 0, 4);
                    var protocolVersion = BitConverter.ToInt32(bProtocolVersion, 0);
                    if (protocolVersion != Protocol.Version)
                    {
                        throw new Exception("Invalid protocol version");
                    }

                    var bPacketId = new byte[4];
                    stream.Read(bPacketId, 0, 4);
                    var packetId = (Protocols)BitConverter.ToInt32(bPacketId, 0);

                    // ReSharper disable once SwitchStatementMissingSomeCases
                    switch (packetId)
                    {
                    case Protocols.LOGIN_ACK:
                        var loginAck = Serializer.Deserialize <PPNetLib.Contracts.LoginAck>(stream);
                        OnLoginAck?.Invoke(loginAck);
                        break;

                    case Protocols.ZONECOUNT_ACK:
                        var zoneCountAck = Serializer.Deserialize <PPNetLib.Contracts.ZoneCountAck>(stream);
                        OnZoneCountAck?.Invoke(zoneCountAck);
                        break;

                    case Protocols.ZONELIST_ACK:
                        var zoneListAck = Serializer.Deserialize <PPNetLib.Contracts.ZoneListAck>(stream);
                        OnZoneListAck?.Invoke(zoneListAck);
                        break;

                    case Protocols.INSERTZONE_ACK:
                        var zoneInsertAck = Serializer.Deserialize <PPNetLib.Contracts.InsertZoneAck>(stream);
                        OnZoneInsertAck?.Invoke(zoneInsertAck);
                        OnZoneInsertAck = null;
                        break;

                    case Protocols.INSERTPOINT_ACK:
                        var pointInsertAck = Serializer.Deserialize <PPNetLib.Contracts.InsertPointAck>(stream);
                        OnPointInsertAck?.Invoke(pointInsertAck);
                        OnPointInsertAck = null;
                        break;

                    case Protocols.CITYLIST_ACK:
                        var cityListAck = Serializer.Deserialize <PPNetLib.Contracts.CityListAck>(stream);
                        OnCityListAck?.Invoke(cityListAck);
                        break;

                    case Protocols.USERLIST_ACK:
                        var userListAck = Serializer.Deserialize <PPNetLib.Contracts.UserListAck>(stream);
                        OnUserListAck?.Invoke(userListAck);
                        break;

                    case Protocols.ISDUPLICATEUSER_ACK:
                        var isDuplicateUserAck = Serializer.Deserialize <PPNetLib.Contracts.IsDuplicateUserAck>(stream);
                        OnIsDuplicateUserAck?.Invoke(isDuplicateUserAck);
                        OnIsDuplicateUserAck = null;
                        break;

                    case Protocols.POINTUPDATED_ACK:
                        var pointUpdatedAck =
                            Serializer.Deserialize <PPNetLib.Contracts.SynchroniseAcks.PointUpdatedAck>(stream);
                        OnPointUpdatedAck?.Invoke(pointUpdatedAck);
                        break;

                    case Protocols.ZONEINFOUPDATED_ACK:
                        var zoneInfoUpdatedAck =
                            Serializer.Deserialize <PPNetLib.Contracts.SynchroniseAcks.ZoneInfoUpdatedAck>(stream);
                        OnZoneInfoUpdatedAck?.Invoke(zoneInfoUpdatedAck);
                        break;

                    case Protocols.LOGINDUPLICATE_ACK:
                        OnLoginDuplicateAck?.Invoke();
                        break;

                    case Protocols.SHUTDOWN_ACK:
                        var shutdownAck = Serializer.Deserialize <PPNetLib.Contracts.ShutdownAck>(stream);
                        OnShutdownAck?.Invoke(shutdownAck);
                        break;

                    case Protocols.SERVERMONITOR_ACK:
                        var serverMonitorAck = Serializer.Deserialize <PPNetLib.Contracts.Monitor.ServerMonitorAck>(stream);
                        OnServerMonitorAck?.Invoke(serverMonitorAck);
                        break;

                    case Protocols.ONLINEUSERS_ACK:
                        var onlineUsersAck = Serializer.Deserialize <PPNetLib.Contracts.Monitor.OnlineUsersAck>(stream);
                        OnOnlineUsersAck?.Invoke(onlineUsersAck);
                        break;

                    case Protocols.ABORTSESSION_ACK:
                        OnConnectionError?.Invoke(new Exception("Session aborted"));
                        break;

                    case Protocols.LISTBANNEDIPS_ACK:
                        var listBannedIps = Serializer.Deserialize <PPNetLib.Contracts.Monitor.ListBannedIpsAck>(stream);
                        OnListBannedIpsAck?.Invoke(listBannedIps);
                        break;

                    case Protocols.COMMAND_ACK:
                        var commandAck = Serializer.Deserialize <PPNetLib.Contracts.Monitor.CommandAck>(stream);
                        OnCommandAck?.Invoke(commandAck);
                        break;
                    }
                    Debug.WriteLine("Received PID {0}", packetId);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            return(true);
        }
Esempio n. 3
0
        private void onLoginAck(ulong playerID)
        {
            player.SetPlayerID(playerID);

            OnLoginAck?.Invoke(playerID);
        }