本文整理汇总了C#中Session.Send方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Send方法的具体用法?C# Session.Send怎么用?C# Session.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session.Send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPing
public virtual void OnPing(Session session, byte[] data)
{
WebSocketEventPackage events = Events as WebSocketEventPackage;
if (events != null) events.FirePingEvent(session, data);
session.Send(WebMessage.CreatePongMessage(data));
}
示例2: messager1_DataReceived
static void messager1_DataReceived(Messager<SessionData3> sender, Session<SessionData3> e, ArraySegment<byte> dataSegment)
{
var data = Encoding.Default.GetString(dataSegment.Array, dataSegment.Offset, dataSegment.Count);
Console.WriteLine("[messager1_DataReceived], " + data);
var num = data.Split(',').Select(x => int.Parse(x)).ToArray();
Console.WriteLine("[messager1_DataSend], " + (num[0] + num[1]).ToString());
e.Send((num[0] + num[1]).ToString());
}
示例3: HandlePing
public static void HandlePing(object packet, Session session)
{
var ping = new PacketPing()
{
Time = (uint)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds
};
session.Send(ping);
}
示例4: HandleLobbyLookup
public static void HandleLobbyLookup(object packet, Session session)
{
var lobbyLookup = new PacketLobbyLookup()
{
Ip = ConfigManager.Config.Network.Host,
Port = ConfigManager.Config.Network.LobbyPort,
};
session.Send(lobbyLookup);
}
示例5: HandleDidYouKnow
public static void HandleDidYouKnow(object packet, Session session)
{
// TODO: implement this correctly
var didYouKnow = new PacketDidYouKnow()
{
Id = 69u,
Hint = "Welcome to this RelentlessZero server!"
};
session.Send(didYouKnow);
}
示例6: HandleOverallStats
public static void HandleOverallStats(object packet, Session session)
{
var overallStats = new PacketOverallStats()
{
ServerName = ConfigManager.Config.Server.Name,
PlayersOnline = WorldManager.GetSessionCount(),
PlayersOnline24h = 0u,
// TODO: implement this correctly
TopRanked = new string[0],
WeeklyWinners = new string[0]
};
session.Send(overallStats);
}
示例7: sendAddOrClose
static void sendAddOrClose(Session<SessionData3> session)
{
Console.WriteLine("sendAddOrClose");
if (RandomHelper.NextRandomInt(0, 6) == 2) {
session.Close();
}
else {
session.Data.a = RandomHelper.NextRandomInt(0, 1000000);
session.Data.b = RandomHelper.NextRandomInt(0, 10000000);
var sent = session.Data.a + "," + session.Data.b;
session.Send(Encoding.Default.GetBytes(sent));
Console.WriteLine("[messager2_DataSend], " + sent);
Console.OpenStandardOutput().Flush();
}
}
示例8: Handle
public override void Handle(Session session)
{
if (Program.DelayManager.AddAndCheck(session, 2.5))
return;
var room = Program.RoomManager.Get(session.Room);
if (room == null)
{
session.SendSysMessage("Room does not exist.");
return;
}
if (room.IsPrivate)
{
if (session.Account == null || room.IsBanned(session.Account.Name))
return;
}
List<HistoryLine> lines;
if (Util.DateTimeFromUnixTimestamp(AfterDate) > DateTime.UtcNow.AddDays(-7))
{
var cmd = new SqlCommand("SELECT * FROM rohbot.chathistory WHERE chat=lower(:chat) AND date<:afterdate ORDER BY date DESC LIMIT 100;");
cmd["chat"] = session.Room;
cmd["afterdate"] = AfterDate;
lines = cmd.Execute().Select(r => (HistoryLine)HistoryLine.Read(r)).Reverse().ToList();
}
else
{
lines = new List<HistoryLine>();
}
var history = new ChatHistory
{
Name = room.RoomInfo.Name,
ShortName = room.RoomInfo.ShortName,
Requested = true,
Lines = lines
};
session.Send(history);
}
示例9: Disconnect
public void Disconnect(Session session)
{
if (session.IsConnected)
{
Message message = MessageFactory.Current.ReserveMessage(typeof(LeaveRequestMessage));
session.Send(message);
MessageFactory.Current.ReleaseMessage(message);
}
else
{
throw new Exception("Not connected.");
}
}
示例10: HandleJoinBattle
public static void HandleJoinBattle(object packet, Session session)
{
// TODO : handle better AI avatar
Battle battle;
if (BattleManager.Battles.TryGetValue(session.Player.Id, out battle) && WorldManager.AddPlayerSession(session))
{
BattleSide playerSide = battle.FindSideByUsername(session.Player.Username);
Avatar playerAvatar = session.Player.Avatar;
Avatar opponentAvatar;
Session opponentSession = WorldManager.GetPlayerSession(playerSide.OpponentSide.PlayerName);
if (opponentSession == null)
opponentAvatar = new Avatar();
else
opponentAvatar = opponentSession.Player.Avatar;
Avatar whiteAvatar;
Avatar blackAvatar;
if (playerSide.Color == PlayerColor.white)
{
whiteAvatar = playerAvatar;
blackAvatar = opponentAvatar;
}
else
{
whiteAvatar = opponentAvatar;
blackAvatar = playerAvatar;
}
var gameInfo = new PacketGameInfo()
{
White = battle.WhiteSide.PlayerName,
Black = battle.BlackSide.PlayerName,
GameType = battle.Type,
GameId = 1,
Color = playerSide.Color,
roundTimerSeconds = battle.RoundTimeSeconds,
Phase = battle.Phase,
WhiteAvatar = whiteAvatar,
BlackAvatar = blackAvatar,
WhiteIdolTypes = new PacketIdolTypes()
{
ProfileId = battle.WhiteSide.PlayerId,
Type = "DEFAULT",
Idol1 = 0,
Idol2 = 0,
Idol3 = 0,
Idol4 = 0,
Idol5 = 0,
},
BlackIdolTypes = new PacketIdolTypes()
{
ProfileId = battle.BlackSide.PlayerId,
Type = "DEFAULT",
Idol1 = 0,
Idol2 = 0,
Idol3 = 0,
Idol4 = 0,
Idol5 = 0,
},
CustomSettings = new List<string>(),
RewardForIdolKill = battle.RewardForIdolKill,
NodeId = ((IPEndPoint)session.Socket.LocalEndPoint).Address.ToString(),
Port = (uint)ConfigManager.Config.Network.BattlePort,
MaxTierRewardMultiplier = 0.5f,
TierRewardMultiplierDelta = new List<float>(),
WhiteIdols = battle.WhiteSide.Idols,
BlackIdols = battle.BlackSide.Idols
};
session.Send(gameInfo);
}
else
{
LogManager.Write("JoinBattle", "player {0} failed to join battle ! Either battle not created or could not add player session!", session.Player.Username);
}
}
示例11: 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);
}
}
}
示例12: HandleRoomsList
public static void HandleRoomsList(object packet, Session session)
{
var roomsList = new PacketRoomsList()
{
Rooms = LobbyManager.GenerateRoomList()
};
session.Send(roomsList);
}
示例13: HandlePlaySinglePlayerQuickMatch
public static void HandlePlaySinglePlayerQuickMatch(object packet, Session session)
{
if (BattleManager.Battles.ContainsKey(session.Player.Id))
{
LogManager.Write("Player", "Player {0} wants to play several skirmish at once ! Not possible !", session.Player.Id);
return;
}
// 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);
}*/
// TODO : handle AI robot name and deck
var newBattle = new Battle(BattleType.SP_QUICKMATCH);
newBattle.WhiteSide = new BattleSide(session.Player.Id, session.Player.Username, PlayerColor.white);
newBattle.BlackSide = new BattleSide(UInt16.MaxValue, "Easy AI", PlayerColor.black);
newBattle.WhiteSide.OpponentSide = newBattle.BlackSide;
newBattle.BlackSide.OpponentSide = newBattle.WhiteSide;
BattleManager.Battles[session.Player.Id] = newBattle;
var battleRedirect = new PacketBattleRedirect()
{
IP = ConfigManager.Config.Network.Host,
Port = (uint)ConfigManager.Config.Network.BattlePort
};
session.Send(battleRedirect);
}
示例14: HandleGameChallengeDecline
public static void HandleGameChallengeDecline(object packet, Session session)
{
var gameChallengeDecline = (PacketGameChallengeDecline)packet;
var opponentSession = WorldManager.GetPlayerSession(gameChallengeDecline.ProfileId);
if (opponentSession == null)
{
LogManager.Write("Player", "Player {0} tried to decline challange non existant player {1} to a battle!",
session.Player.Id, gameChallengeDecline.ProfileId);
}
var packetGameChallengeResponse = new PacketGameChallengeResponse()
{
From = opponentSession.Player.GeneratePacketProfile(),
To = session.Player.GeneratePacketProfile(),
Status = "DECLINE"
};
opponentSession.Send(packetGameChallengeResponse);
session.Send(packetGameChallengeResponse);
}
示例15: DeclineConnection
private void DeclineConnection(Session session, Message joinRequestMessage)
{
JoinResponseMessage joinResponseMessage = (JoinResponseMessage)MessageFactory.Current.ReserveMessage(typeof(JoinResponseMessage));
joinResponseMessage.RequestMessageId = joinRequestMessage.MessageId;
joinResponseMessage.FailureCode = MxpResponseCodes.UNAUTHORIZED_OPERATION;
joinResponseMessage.ProgramName = m_programName;
joinResponseMessage.ProgramMajorVersion = m_programMajorVersion;
joinResponseMessage.ProgramMinorVersion = m_programMinorVersion;
joinResponseMessage.ProtocolMajorVersion = MxpConstants.ProtocolMajorVersion;
joinResponseMessage.ProtocolMinorVersion = MxpConstants.ProtocolMinorVersion;
joinResponseMessage.ProtocolSourceRevision = MxpConstants.ProtocolSourceRevision;
session.Send(joinResponseMessage);
session.SetStateDisconnected();
}