… | |
… | |
1548 | |
1548 | |
1549 | Expand crossfire pod fragments into protocol xml. |
1549 | Expand crossfire pod fragments into protocol xml. |
1550 | |
1550 | |
1551 | =cut |
1551 | =cut |
1552 | |
1552 | |
|
|
1553 | use re 'eval'; |
|
|
1554 | |
|
|
1555 | my $group; |
|
|
1556 | my $interior; $interior = qr{ |
|
|
1557 | (?: |
|
|
1558 | \ (.*?)\ (?{ $group = $^N }) |
|
|
1559 | | < (??{$interior}) > |
|
|
1560 | ) |
|
|
1561 | }x; |
|
|
1562 | |
1553 | sub expand_cfpod { |
1563 | sub expand_cfpod { |
1554 | ((my $self), (local $_)) = @_; |
1564 | my ($self, $pod) = @_; |
1555 | |
1565 | |
1556 | # escape & and < |
1566 | my $xml; |
1557 | s/&/&/g; |
|
|
1558 | s/(?<![BIUGHT])</</g; |
|
|
1559 | |
1567 | |
1560 | # this is buggy, it needs to properly take care of nested <'s |
1568 | while () { |
|
|
1569 | if ($pod =~ /\G( (?: [^BCGHITU]+ | .(?!<) )+ )/xgcs) { |
|
|
1570 | $group = $1; |
1561 | |
1571 | |
1562 | 1 while |
1572 | $group =~ s/&/&/g; |
1563 | # replace B<>, I<>, U<> etc. |
1573 | $group =~ s/</</g; |
1564 | s/B<([^\>]*)>/<b>$1<\/b>/ |
1574 | |
1565 | || s/I<([^\>]*)>/<i>$1<\/i>/ |
1575 | $xml .= $group; |
1566 | || s/U<([^\>]*)>/<u>$1<\/u>/ |
1576 | } elsif ($pod =~ m%\G |
1567 | || s/T<([^\>]*)>/<big><b>$1<\/b><\/big>/ |
1577 | ([BCGHITU]) |
1568 | # replace G<male|female> tags |
1578 | < |
1569 | || s{G<([^>|]*)\|([^>]*)>}{ |
1579 | (?: |
1570 | $self->gender ? $2 : $1 |
1580 | ([^<>]*) (?{ $group = $^N }) |
1571 | }ge |
1581 | | < $interior > |
1572 | # replace H<hint text> |
1582 | ) |
1573 | || s{H<([^\>]*)>} |
1583 | > |
|
|
1584 | %gcsx |
1574 | { |
1585 | ) { |
|
|
1586 | my ($code, $data) = ($1, $group); |
|
|
1587 | |
|
|
1588 | if ($code eq "B") { |
|
|
1589 | $xml .= "<b>" . expand_cfpod ($self, $data) . "</b>"; |
|
|
1590 | } elsif ($code eq "I") { |
|
|
1591 | $xml .= "<i>" . expand_cfpod ($self, $data) . "</i>"; |
|
|
1592 | } elsif ($code eq "U") { |
|
|
1593 | $xml .= "<u>" . expand_cfpod ($self, $data) . "</u>"; |
|
|
1594 | } elsif ($code eq "C") { |
|
|
1595 | $xml .= "<tt>" . expand_cfpod ($self, $data) . "</tt>"; |
|
|
1596 | } elsif ($code eq "T") { |
|
|
1597 | $xml .= "<big><b>" . expand_cfpod ($self, $data) . "</b></big>"; |
|
|
1598 | } elsif ($code eq "G") { |
|
|
1599 | my ($male, $female) = split /\|/, $data; |
|
|
1600 | $data = $self->gender ? $female : $male; |
|
|
1601 | $xml .= expand_cfpod ($self, $data); |
|
|
1602 | } elsif ($code eq "H") { |
1575 | ("<fg name=\"lightblue\">[$1 (Use hintmode to suppress hints)]</fg>", |
1603 | $xml .= ("<fg name=\"lightblue\">[" . expand_cfpod ($self, $data) . " (Use hintmode to suppress hints)]</fg>", |
1576 | "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>", |
1604 | "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>", |
1577 | "") |
1605 | "") |
1578 | [$self->{hintmode}] |
1606 | [$self->{hintmode}]; |
|
|
1607 | } else { |
|
|
1608 | $xml .= "error processing '$code($data)' directive"; |
1579 | }ge; |
1609 | } |
|
|
1610 | } else { |
|
|
1611 | if ($pod =~ /\G(.+)/) { |
|
|
1612 | warn "parse error while expanding $pod (at $1)"; |
|
|
1613 | } |
|
|
1614 | last; |
|
|
1615 | } |
|
|
1616 | } |
1580 | |
1617 | |
|
|
1618 | for ($xml) { |
1581 | # create single paragraphs (very hackish) |
1619 | # create single paragraphs (very hackish) |
1582 | s/(?<=\S)\n(?=\w)/ /g; |
1620 | s/(?<=\S)\n(?=\w)/ /g; |
1583 | |
1621 | |
1584 | # compress some whitespace |
1622 | # compress some whitespace |
1585 | s/\s+\n/\n/g; # ws line-ends |
1623 | s/\s+\n/\n/g; # ws line-ends |
1586 | s/\n\n+/\n/g; # double lines |
1624 | s/\n\n+/\n/g; # double lines |
1587 | s/^\n+//; # beginning lines |
1625 | s/^\n+//; # beginning lines |
1588 | s/\n+$//; # ending lines |
1626 | s/\n+$//; # ending lines |
|
|
1627 | } |
1589 | |
1628 | |
1590 | $_ |
1629 | $xml |
1591 | } |
1630 | } |
1592 | |
1631 | |
1593 | sub hintmode { |
1632 | sub hintmode { |
1594 | $_[0]{hintmode} = $_[1] if @_ > 1; |
1633 | $_[0]{hintmode} = $_[1] if @_ > 1; |
1595 | $_[0]{hintmode} |
1634 | $_[0]{hintmode} |
… | |
… | |
2666 | the message, with C<log> being the default. If C<$color> is negative, suppress |
2705 | the message, with C<log> being the default. If C<$color> is negative, suppress |
2667 | the message unless the client supports the msg packet. |
2706 | the message unless the client supports the msg packet. |
2668 | |
2707 | |
2669 | =cut |
2708 | =cut |
2670 | |
2709 | |
|
|
2710 | # non-persistent channels (usually the info channel) |
2671 | our %CHANNEL = ( |
2711 | our %CHANNEL = ( |
2672 | "c/identify" => { |
2712 | "c/identify" => { |
2673 | id => "infobox", |
2713 | id => "infobox", |
2674 | title => "Identify", |
2714 | title => "Identify", |
2675 | reply => undef, |
2715 | reply => undef, |
… | |
… | |
2690 | "c/lookat" => { |
2730 | "c/lookat" => { |
2691 | id => "infobox", |
2731 | id => "infobox", |
2692 | title => "Look", |
2732 | title => "Look", |
2693 | reply => undef, |
2733 | reply => undef, |
2694 | tooltip => "What you saw there", |
2734 | tooltip => "What you saw there", |
|
|
2735 | }, |
|
|
2736 | "c/who" => { |
|
|
2737 | id => "infobox", |
|
|
2738 | title => "Players", |
|
|
2739 | reply => undef, |
|
|
2740 | tooltip => "Shows players who are currently online", |
|
|
2741 | }, |
|
|
2742 | "c/body" => { |
|
|
2743 | id => "infobox", |
|
|
2744 | title => "Body Parts", |
|
|
2745 | reply => undef, |
|
|
2746 | tooltip => "Shows which body parts you posess and are available", |
|
|
2747 | }, |
|
|
2748 | "c/uptime" => { |
|
|
2749 | id => "infobox", |
|
|
2750 | title => "Uptime", |
|
|
2751 | reply => undef, |
|
|
2752 | tooltip => "How long the server has been running since last restart", |
|
|
2753 | }, |
|
|
2754 | "c/mapinfo" => { |
|
|
2755 | id => "infobox", |
|
|
2756 | title => "Map Info", |
|
|
2757 | reply => undef, |
|
|
2758 | tooltip => "Information related to the maps", |
2695 | }, |
2759 | }, |
2696 | ); |
2760 | ); |
2697 | |
2761 | |
2698 | sub cf::client::send_msg { |
2762 | sub cf::client::send_msg { |
2699 | my ($self, $channel, $msg, $color, @extra) = @_; |
2763 | my ($self, $channel, $msg, $color, @extra) = @_; |