本文整理汇总了C#中Session.SendOkPacket方法的典型用法代码示例。如果您正苦于以下问题:C# Session.SendOkPacket方法的具体用法?C# Session.SendOkPacket怎么用?C# Session.SendOkPacket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session.SendOkPacket方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleRoomExit
public static void HandleRoomExit(object packet, Session session)
{
var roomExit = (PacketRoomExit)packet;
if (LobbyManager.RemovePlayer(roomExit.RoomName, session.Player))
session.SendOkPacket("RoomExit");
else
session.Player.SendRoomMessage("Message", "Failed to exit room " + roomExit.RoomName + "!");
}
示例2: HandleGameChallengeAccept
public static void HandleGameChallengeAccept(object packet, Session session)
{
var gameChallangeAccept = (PacketGameChallengeAccept)packet;
Session opponentSession = WorldManager.GetPlayerSession(gameChallangeAccept.ProfileId);
if (opponentSession != null)
{
if (BattleManager.Battles.ContainsKey(session.Player.Id))
LogManager.Write("Lobby handler", "player {0} wants to play several quickmatches at once ! Not possible !", session.Player.Id);
else if (BattleManager.Battles.ContainsKey(opponentSession.Player.Id))
LogManager.Write("Lobby handler", "player {0} wants to play several quickmatches at once ! Not possible !", opponentSession.Player.Id);
else
{
// TODO: handle this better
/*BattleType[] typesToAbort = new BattleType[3] { BattleType.MP_QUICKMATCH, BattleType.MP_RANKED, BattleType.MP_LIMITED };
foreach (BattleType battleType in typesToAbort)
{
var cancelQueue = new PacketGameMatchQueueStatus()
{
InQueue = false,
GameType = battleType
};
session.Send(cancelQueue);
opponentSession.Send(cancelQueue);
}*/
PacketGameChallengeResponse gameChallenge = new PacketGameChallengeResponse()
{
From = opponentSession.Player.GeneratePacketProfile(),
To = session.Player.GeneratePacketProfile(),
Status = "ACCEPT"
};
opponentSession.Send(gameChallenge);
session.SendOkPacket("GameChallengeAccept");
Random random = new Random();
PlayerColor challengerColor, challengedColor;
if (random.Next(2) > 0)
{
challengerColor = PlayerColor.white;
challengedColor = PlayerColor.black;
}
else
{
challengedColor = PlayerColor.white;
challengerColor = PlayerColor.black;
}
Battle newBattle = new Battle(BattleType.MP_UNRANKED);
BattleSide challengedSide = new BattleSide(session.Player.Id, session.Player.Username, challengedColor);
BattleSide challengerSide = new BattleSide(opponentSession.Player.Id, opponentSession.Player.Username, challengerColor);
challengedSide.OpponentSide = challengerSide;
challengerSide.OpponentSide = challengedSide;
newBattle.WhiteSide = challengerColor == PlayerColor.white ? challengerSide : challengedSide;
newBattle.BlackSide = challengerColor == PlayerColor.black ? challengerSide : challengedSide;
BattleManager.Battles[session.Player.Id] = newBattle;
BattleManager.Battles[opponentSession.Player.Id] = newBattle;
var battleRedirect = new PacketBattleRedirect()
{
IP = ((IPEndPoint)session.Socket.LocalEndPoint).Address.ToString(),
Port = (uint)ConfigManager.Config.Network.BattlePort
};
session.Send(battleRedirect);
opponentSession.Send(battleRedirect);
}
}
}
示例3: HandleRoomEnterMulti
public static void HandleRoomEnterMulti(object packet, Session session)
{
var roomEnterMulti = (PacketRoomEnterMulti)packet;
if (roomEnterMulti.RoomNames.Count > 10)
{
LogManager.Write("Lobby Handler", "Player {0} tried to enter {1} rooms via 'RoomEnterMulti', this is more then the maximum allowed!",
session.Player.Username, roomEnterMulti.RoomNames.Count);
return;
}
foreach (string roomName in roomEnterMulti.RoomNames)
{
if (!LobbyManager.AddPlayer(roomName, session.Player, false))
{
session.Player.SendRoomMessage("Message", "Failed to join room " + roomName + "!");
return;
}
}
session.SendOkPacket("RoomEnterMulti");
}
示例4: HandleRoomEnter
public static void HandleRoomEnter(object packet, Session session)
{
var roomEnter = (PacketRoomEnter)packet;
string packetName = packet.GetType().Name.Remove(0, 6);
if (packetName == "RoomEnterFree")
{
if (!LobbyManager.RoomIncremental(roomEnter.RoomName))
{
LogManager.Write("Lobby Handler", "Player {0} tried to enter room {1} via 'RoomEnterFree' but room isn't incremental!",
session.Player.Username, roomEnter.RoomName);
return;
}
// extra check required on 'RoomEnterFree' to prevent error message on reconnect
if (session.Player.CurrentRooms.Contains(roomEnter.RoomName))
return;
}
if (LobbyManager.AddPlayer(roomEnter.RoomName, session.Player))
session.SendOkPacket(packetName);
else
session.Player.SendRoomMessage("Message", "Failed to join room " + roomEnter.RoomName + "!");
}
示例5: HandleGameChallengeRequest
public static void HandleGameChallengeRequest(object packet, Session session)
{
var gameChallengeRequest = (PacketGameChallengeRequest)packet;
var opponentSession = WorldManager.GetPlayerSession(gameChallengeRequest.ProfileId);
if (opponentSession == null)
{
LogManager.Write("Player", "Player {0} tried to challange non existant player {1} to a battle!",
session.Player.Id, gameChallengeRequest.ProfileId);
return;
}
var packetGameChallenge = new PacketGameChallenge()
{
From = session.Player.GeneratePacketProfile(),
ParentalConsent = false
};
opponentSession.Send(packetGameChallenge);
session.SendOkPacket("GameChallengeRequest");
}
示例6: HandleConnect
public static void HandleConnect(object packet, Session session)
{
var firstConnect = (PacketConnect)packet;
string packetName = packet.GetType().Name.Remove(0, 6);
// decrypt login information
string username = Rsa.Decrypt(firstConnect.Username);
string password = Rsa.Decrypt(firstConnect.Password);
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
{
LogManager.Write("Authentication", "Session {0} sent invalid account credentials (empty or whitespace)!", session.IpAddress);
session.SendFatalFailPacket(packetName, "An internal error has occurred!");
return;
}
// handle initial profile data from database
SqlResult accountResult = DatabaseManager.Database.Select("SELECT id, password, salt, adminRole, flags FROM account_info WHERE username = ?", username);
if (accountResult == null || accountResult.Count > 1)
{
LogManager.Write("Authentication", "Failed to lookup account {0} requested by session {1}!", username, session.IpAddress);
session.SendFatalFailPacket(packetName, "Internal Error: Failed to lookup account information!");
return;
}
AuthStatus authStatus = AuthStatus.InvalidCredentials;
if (accountResult.Count == 1)
{
uint accountId = accountResult.Read<uint>(0, "id");
authStatus = GetAuthStatus(accountId, accountResult.Read<string>(0, "password"), accountResult.Read<string>(0, "salt"), username, password);
if (authStatus == AuthStatus.Ok)
{
session.Player = new Player()
{
Id = accountId,
Session = session,
Username = username,
AdminRole = accountResult.Read<AdminRole>(0, "adminRole"),
Flags = accountResult.Read<PlayerFlags>(0, "flags"),
};
// send initial profile data to client
var profileInfo = new PacketProfileInfo
{
Profile = session.Player.GeneratePacketProfile()
};
session.Send(profileInfo);
if (packetName == "FirstConnect")
{
session.SendString(AssetManager.ScrollTemplateCache);
session.SendString(AssetManager.AvatarPartTemplateCache);
// TODO: send other assets here...
// session.SendString("{\"type\":\"GROWTH_START_DECK\",\"msg\":\"Message\"}");
}
// authentication was successful, send packets to move client to main menu
session.SendOkPacket(packetName);
session.Send(new PacketActivateGame());
}
else
session.SendFailPacket(packetName, GetAuthFailStatusString(authStatus));
}
else
session.SendFailPacket(packetName, GetAuthFailStatusString(authStatus));
}
示例7: HandleJoinLobby
public static void HandleJoinLobby(object packet, Session session)
{
// handle remaining profile data from database
SqlResult accountResult = DatabaseManager.Database.Select("SELECT gold, shards, rating FROM account_info WHERE username = ?", session.Player.Username);
if (accountResult == null || accountResult.Count != 1)
{
session.SendFatalFailPacket("JoinLobby", "Failed to lookup account information!");
return;
}
if (!WorldManager.AddPlayerSession(session))
{
// will only fail if 'JoinLobby' is sent before 'Connect', which shouldn't occur normally?
session.SendFatalFailPacket("JoinLobby", "Failed to add player session!");
return;
}
var player = session.Player;
player.Gold = accountResult.Read<uint>(0, "gold");
player.Shards = accountResult.Read<uint>(0, "shards");
player.Rating = accountResult.Read<ushort>(0, "rating");
// send remaining profile data to client
var profileDataInfo = new PacketProfileDataInfo
{
ProfileData = new PacketProfileData()
{
Gold = player.Gold,
Shards = player.Shards,
StarterDeckVersion = 1, // use currently unknown
SpectatePermission = player.HasFlag(PlayerFlags.SpectateAllow) ? (session.Player.HasFlag(PlayerFlags.SpectateHideChat) ? "ALLOW" : "AllOW_CHAT") : "DISALLOW",
AcceptTrades = player.HasFlag(PlayerFlags.AcceptTrades),
AcceptChallenges = player.HasFlag(PlayerFlags.AcceptChallenges),
Rating = player.Rating
}
};
session.Send(profileDataInfo);
player.Avatar.Id = player.Id;
// handle first login
if (player.HasFlag(PlayerFlags.FirstLogin))
{
player.GiveAllScrolls();
// default avatar pieces
player.Avatar.SetAvatar(33, 10, 41, 4, 15);
player.Avatar.SaveAvatar();
player.RemoveFlag(PlayerFlags.FirstLogin);
}
else
{
// load avatar information
SqlResult avatarResult = DatabaseManager.Database.Select("SELECT `head`, `body`, `leg`, `armBack`, `armFront` FROM `account_avatar` WHERE `id` = ?", player.Id);
if (avatarResult == null || avatarResult.Count == 0)
{
session.SendFatalFailPacket("JoinLobby", "Failed to lookup account avatar information!");
return;
}
player.Avatar.SetAvatar(avatarResult.Read<uint>(0, "head"), avatarResult.Read<uint>(0, "body"),
avatarResult.Read<uint>(0, "leg"), avatarResult.Read<uint>(0, "armBack"), avatarResult.Read<uint>(0, "armFront"));
}
player.LoadScrolls();
player.LoadDecks();
// TODO: friend stuff here
session.SendOkPacket("JoinLobby");
}